jquery - Using AJAX/PHP/mysqli to create a load more button -


in code below trying create load more button using ajax. have main.php includes php code calling blogs database initially, jquery code , load more button. have ajax_more.php calls more data database when load more clicked. load more buttons displayed , when clicked change loading , disappear. nothing else happens , main.php still shows 2 initial blogs call first. please code , code has gone wrong.

main.php

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript">     $(document).ready(function () {         $(document).on('click', '.show_more', function () {             var id = $(this).attr('id');             $('.show_more').hide();             $('.loding').show();             $.ajax({                 type: 'post',                 url: 'ajax_more.php',                 data: 'id=' + id,                 success: function (html) {                     $('#show_more_main' + id).remove();                     $('.columns').append(html);                 }             });         });     }); </script>  <?php $query = "     select blogs_id, title, body, posted_by, full_name, bio, posted, category     blogs          inner join categories              on categories.category_id=blogs.category_id      category='cat1' or category='catt2' or category='cat3' or category='cat4'      order blogs_id desc      limit 2 "; $result = mysqli_query($con,$query); $rowcount = mysqli_num_rows($result);  if($rowcount > 0){     while ($row = mysqli_fetch_assoc($result)) {         $blogs_id = $row['blogs_id'];         $title = $row['title'];         $body = $row['body'];         $posted_by = $row['posted_by'];         $full_name = $row['full_name'];         $bio = $row['bio'];         $posted = $row['posted'];          echo "             <div class='db'>                 <h2>$title</h2>                 <p>$body</p>                 <p>$bio</p>             </div>         "; ?> <div class="show_more_main" id="show_more_main<?php echo $blogs_id; ?>">     <span id="<?php echo $blogs_id; ?>" class="show_more" title="load more posts">show more</span>     <span class="loding" style="display: none;"><span class="loding_txt">loading…</span></span> </div> 

ajax_more.php

<?php if(isset($_post["blogs_id"]) && !empty($_post["blogs_id"])) {     $query = "         select blogs_id, title, body, posted_by, full_name, bio, posted, category          blogs              inner join categories on categories.category_id=blogs.category_id          category='entertainment' or category='politics' or category='sports' or category='travel'             , blogs_id < ".$_post['blogs_id']."          order blogs_id desc          limit 2     ";     $result = mysqli_query($con,$query);     $rowcount = mysqli_num_rows($result);     if($rowcount > 0){         while ($row = mysqli_fetch_assoc($result)) {             $blogs_id = $row['blogs_id'];             $title = $row['title'];             $body = $row['body'];             $posted_by = $row['posted_by'];             $full_name = $row['full_name'];             $bio = $row['bio'];             $posted = $row['posted'];              echo "                 <div class='db'>                 <h2>$title</h2>                 <p>$body</p>                 <p>$bio</p>                 </div>             "; ?> 

you should change query this

$query = "select blogs_id, title, body, posted_by, full_name, bio, posted, category  blogs inner join categories on categories.category_id=blogs.category_id (category='entertainment' or category='politics' or category='sports' or category='travel')   , blogs_id < " . $_post['blogs_id'] . " order blogs_id desc limit 2"; 

all or's must enclosed in brackets....


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -