Reputation: 61
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
Upvotes: 2
Views: 17384
Reputation: 647
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>
Upvotes: 2
Reputation: 11869
try setting $list to a javascript variable
. like:
var list=<?php echo $list?>;
then pass it the way you are passing var load
.
Upvotes: 5