【问题标题】:jquery scrollextendjquery 滚动扩展
【发布时间】:2012-09-05 16:46:21
【问题描述】:

我在使用 jquery scrollextend 插件时遇到了一些问题。目标是从 load_messages.php 中获取一些 html 元素并将其插入到 html 页面中。问题是当我重新加载 html 页面时(即多次调用 load_messages.php)我得到了错误:

注意:未定义变量:functions.php 中的数据。

我无法弄清楚究竟是什么导致了这个问题,因为之前定义了 php 变量 $data。有人可以帮忙吗?

jquery代码如下:

//scroll
$('.scroll_container').scrollExtend(
        {
            'target': '#wall_container',
            'url': 'load_messages.php',


        }
    );

load_messages.php 包含以下代码(我省略了不必要的代码块):

<?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);
?>

function.php中的更新函数如下:

  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;

}

【问题讨论】:

    标签: php jquery jquery-plugins


    【解决方案1】:

    您在 while 循环内初始化 $data,这意味着它不可用于循环外的任何内容。如果要存储循环中的值,请在循环外初始化变量。

    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());
    
         $data = array();
         while($row=mysql_fetch_array($query))
         {
             $data[]=$row;
         }
         return $data;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 2020-10-31
      • 2011-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多