i’m having some problem with jquery scrollextend plugin. the objective was to to get some html elements from load_messages.php and insert it into an html page. The problem is that when i reload the html page (i.e call the load_messages.php more than once) i get the error:
Notice:Undefined variable: data in functions.php.
I couldn’t figure out exactly what is causing this problem as the php variable $data is previously defined. anyone can please help?
the jquery code is shown below:
//scroll
$('.scroll_container').scrollExtend(
{
'target': '#wall_container',
'url': 'load_messages.php',
}
);
the load_messages.php contains the following code(i omitted the unnecessary code blocks) :
<?php
include_once 'functions.php';
$user_id=$_SESSION['user_id'];
$Wall = new Wall_Updates();
$table="friends".$user_id;
$updatesarray=$Wall->Updates($table,$user_id,$upper_limit,$lower_limit);
?>
The update function in function.php is the following:
public function Updates($table,$user_id,$upper_limit,$lower_limit)
{
$query = mysql_query("SELECT user.user_id, first_name, post_content,post_id,UNIX_TIMESTAMP( created ) AS time
FROM user, posts
WHERE (
user.user_id
IN (
SELECT friends_id
FROM $table)
OR user.user_id =$user_id)
AND user.user_id = posts.user_id
order by post_id desc
LIMIT $lower_limit , $upper_limit") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
$data[]=$row;
}
return $data;
}
You’re initializing $data inside your while loop, which means that it’s not available to anything outside of the loop. If you want to store values from a loop, initialize the variable outside of the loop.