JQuery smaller / larger button set in php foreach

I want to show a message to everyone. My condition is the 1st publication of the 5th message and hiding another message using the button show more, if the cycle has more than 5 messages, then when I click the "Show more" button, another message will be displayed and hide the button show moreand show the button less more. If the message has less than 5, then the button is not displayed show more. How can I do this using jQuery?

<?php
        foreach ($hotel_data as $key => $hoteldata)
    {
        //Show 3 lowest price of hotel link
        if(isset($hoteldata[0]->rooms)){
            /*$ii = 0;*/
            foreach ($hoteldata[0]->rooms as $key => $bookinginfo) {
                ?> 
                <tr>
                <td class="">
                    <div class="hotel_name">
                        <?php echo $bookinginfo->desc; ?>
                    </div>
                </td>


                <td class="booking-img">
                    <img src="http://pics.avs.io/hl_gates/100/30/<?php echo $bookinginfo->agencyId; ?>.png"/>
                </td>
                <td>
                    <div class="hotel-price">
                        Price : $ <?php echo $bookinginfo->price; ?>
                    </div>
                </td>
                <td class="booking-url">
                    <a href="<?php echo $bookinginfo->fullBookingURL; ?>" class="btn btn-info" role="button" data-toggle="tooltip" data-placement="top" title="<?php echo $bookinginfo->agencyName; ?>">  BOOK NOW</a>
                </td>
                </tr>
                <?php
                /*$ii++;
                if($ii > 2){
                    break;
                }*/
            }
        }
    }
?>
+4
source share
2 answers

You need to rethink your strategy. What you want can be achieved with AJAX calls. So you need to write your loop using JS / jQuery. PHP will only process message searches.

, AJAX, POST- PHP script, , . PHP , , , JSON, JS HTML.

AJAX ( 5), , " ".

+1

, 5 " ". . :

<?php
    // Get count
    $count = count($hotel_data);
    foreach ($hotel_data as $key => $hoteldata) {
        //Show 3 lowest price of hotel link
        if(isset($hoteldata[0]->rooms)) {
            /*$ii = 0;*/
            foreach ($hoteldata[0]->rooms as $key => $bookinginfo) {
                ?> 
                <tr>
                    <td class="">
                        <div class="hotel_name">
                            <?php echo $bookinginfo->desc; ?>
                        </div>
                    </td>


                    <td class="booking-img">
                        <img src="http://pics.avs.io/hl_gates/100/30/<?php echo $bookinginfo->agencyId; ?>.png"/>
                    </td>
                    <td>
                        <div class="hotel-price">
                            Price : $ <?php echo $bookinginfo->price; ?>
                        </div>
                    </td>
                    <td class="booking-url">
                        <a href="<?php echo $bookinginfo->fullBookingURL; ?>" class="btn btn-info" role="button" data-toggle="tooltip" data-placement="top" title="<?php echo $bookinginfo->agencyName; ?>">  BOOK NOW</a>
                    </td>
                </tr>
                <?php
            }
        }

        if ($count>5) {
            // Code for "show more" button
        }
    }
?>

css display: none;. jQuery script " " , . , " ".

0

Source: https://habr.com/ru/post/1688286/


All Articles