2

I have a auto load page and i need to be able to retrieve the data based on a variable as that variable must bring back a specific value. The code below is based on retrieving all the data.But i only need a select few which is based on the $list

Page.php

<?php
  <div class="page-main ">
  $query="SELECT * FROM page WHERE page_id='$list'"; 
  $counting="SELECT * FROM page WHERE page_id='$list'";
  $rows=mysqli_query($connection,$counting);
  $rows_counts=mysqli_num_rows($rows);
  $results=mysqli_query($connection,$query);
  confirm_query($results);
?>

 <div class="loader">
 <img src="loader.gif" alt="loading gif"/>

 </div> 


</div> <!--close page main -->

here is the jquery passing to ajax (it is on same page)

$(document).ready(function(){

$('.loader').hide();  

var load=0;

$.post("ajax.php",{load:load},function(data){  // somehow i need to pass $list to here



      $('.page-main').append(data);


     }); // close ajax
$(window).scroll(function(){


   if($(window).scrollTop() == $(document).height() - $(window).height())
   {
        $('.loader').show();

     load++; 

     $.post("ajax.php",{load:load},function(data){

      $('.page-main').append(data);

  $('.loader').hide();
     }); // close ajax

   };


 });// close window.scroll


});// close document.ready

this is ajax.php ( now here i am getting undefined variable $list, i need to pass $list i am not sure how to pass this $list from php to jquery to ajax.

    $load=htmlentities(strip_tags($_POST["load"])) * 6;

$query="SELECT * FROM page WHERE page_id='$list' ORDER BY page_id DESC  LIMIT ".$load.",6";
$result=mysqli_query($connection,$query);
  confirm_query($result);

// after this while loop ect

2 Answers 2

5

try setting $list to a javascript variable. like:

var list=<?php echo $list?>;

then pass it the way you are passing var load.

Sign up to request clarification or add additional context in comments.

2 Comments

it works thanks man ,i dont have the $link error anymore, but now my data from ajax is not showing , all i see is the loading gif. i added is like this {load:load,catergory:catergory} and ajax tell me undefined variable for load and $Link
i forgot to add echo there my bad i was editing mean while.now try.
2

A possible solution:

<script type="text/javascript">
  var load=0;
  $.ajax({
    type: 'POST',
    url: 'ajax.php',
    data: ({load: load, list: <?php echo $list ?>}),
    success: function(data) {
      $('.page-main').append(data);
    }
  });
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.