I have the following function:
$(window).scroll(function() {
if(ready && labelstatus && $(window).scrollTop() + $(window).height() > $(document).height() - 100){
$('#bottom2').html(loading);
ready = false;
$.ajax({
url: 'scripts/nearbothome.php',
data: {"currentNumber": botnumber, "usersid": usersid},
type: 'post',
success: function(data) {
botnumber = "<?php echo $uniqueend; ?>";
alert("<?php echo $uniqueend; ?>");
$('#oldposts').append(data);
$('#bottom2').html(bottom);
ready = true;
labelstatus = data;
if (data < 1) {
labelstatus = false;
}
}
});
}
});
This all works fine and does as intended EXCEPT for setting the variable 'botnumber' to a new value. The PHP variable which it's supposed to be set to should be returned by the .php file executed by the Ajax ($uniqueend).
See here:
<?php
//open a database connection
include("../db.php");
//receive value
$currNum = $_POST['currentNumber'];
$uidd = $_POST['usersid'];
$results7 = mysql_query("SELECT * FROM `uc_posts` WHERE `postinguser` IN (SELECT `followers` FROM `uc_users` WHERE `id` = $uidd) AND id < $currNum ORDER BY id DESC LIMIT 20");
sleep(1);
while ($row = mysql_fetch_array($results7)) {
echo '<div class="postfeed2">';
$color='#ababab';
$id = $row['id'];
$page = $row['page'];
$postinguser = $row['postinguser'];
$displayname=mysql_fetch_array(mysql_query("SELECT `display_name` FROM `uc_users` WHERE `id` = $postinguser LIMIT 1"));
$username=mysql_fetch_array(mysql_query("SELECT `user_name` FROM `uc_users` WHERE `id` = $postinguser LIMIT 1"));
$checkiffav=mysql_fetch_array(mysql_query("SELECT * FROM `uc_posts` WHERE find_in_set($uidd,`likedby`) AND `id` = $id"));
if ($checkiffav) {
$color='#FF5733';
}
echo '<table><tr><td style="vertical-align: baseline;"><b><img src="blank-user-medium.png" width="50px" height="50px" style="vertical-align: text-top;margin-right: 8px;margin-top: 0px;border: 0px solid #D0D0D0;border-radius: 5px 5px 5px 5px;"></b></td>';
echo '<td style="display: block;word-break: break-word;"><b>' . $displayname[display_name] . '</b>';
echo ' <span style="color:#ababab;">@' . $username[user_name] . '</span>';
echo '<br>' . $page . '';
echo '<br><a href="javascript:void(0)" onclick="javascript:return like(' . $id . ',' . $uidd . ');"><i class="fa fa-heart fa-lg" id="heart' . $id . '" style="margin-top: 5px;color:' . $color . '"></i></a></td></tr></table>';
echo '</div>';
}
$uniqueend2 = mysql_fetch_array(mysql_query("(SELECT * FROM `uc_posts` WHERE `postinguser` IN (SELECT `followers` FROM `uc_users` WHERE `id` = $uidd) AND id < $currNum ORDER BY id DESC LIMIT 20) ORDER BY id ASC"));
$uniqueend = $uniqueend2['id'];
echo $uniqueend;
?>
I can see that it echoes: 184. However on the alert I added to the jQuery in order to verify nothing is there.
I would use json but I have a large amount of php/content data it returns so I'm not sure how that would fit in or work.
Thanks!
echostatement to actually echo out the changed variable? That's not how it works, theechostatement happens on the server, long before the page is sent to the browser, and even longer before the ajax call happens, changing that variable on the server at a later time, won't affect what is echo'ed in the past.