0

所以基本上我有一个load.php页面,它接收一个位置变量并使用它从表格中显示该位置的 6 个结果......但我看到某处有一个错误,因为什么都没有返回......你们能帮忙吗?

这是代码:

  <?php 


error_reporting(0);
session_start();
include '../upload/connect.php';

$start = $_POST['start'];
$id = $_POST['id'];

$sql = mysql_query("SELECT * FROM comments WHERE id='".$id."' ORDER by id DESC LIMIT ".$start." , 6 ") or die(mysql_error());
while ($display = mysql_fetch_assoc($sql))
{
    ?>
    <div id="comments">
    <table>
    <tr>
    <td rowspan="2"><img src="../pic/logo.png" width="100px" /></td>
    <td valign="top"><p style="width:700px;font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;font-size:13px;color:rgba(255,255,255,0.5);">&nbsp;&nbsp;&nbsp;&nbsp;Postat de <?php echo $display['user']; ?> la <?php echo $display['date']; ?> </p></td></td>
    </tr>
    <tr>
    <td width="90%" valign="top"><p style="width:700px;font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif;font-size:13px;color:white;">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $display['comment']; ?></p>
    </tr>
    </table>
    </div>
    <?php
}


?>

和jQuery:

var st = 6;// start position...
    var div_height = $("#mighty_holder").height()/2- 50;
    var doc_scroll = $(document).scrollTop();
    function loadthem (k)
    {
        $.post('../core/load.php',{start: k , id: <?php echo json_encode($id); ?>},
                function(result){
                    $("#comment_holder").append(result);
            }); 
    }

    $(document).scroll(function(){
        if ($("#mighty_holder").height()/2- 50 < $(document).scrollTop())
        {
            loadthem(st);   
            st = parseInt(st) + 7;
        }
    });
4

2 回答 2

0

In your Javascript code, you initialize var st = 6 send 6 to start. Then in the scroll function it is passed as parameter to the loadthem function resulting in 6 being send as start: k in the AJAX POST request to the PHP page. It recovered as $start = $_POST['start'] and inserted in the query like 6 resulting in LIMIT 6, 6. Which will not return any result from the query.

You probably meant to initialize st to 0.

On a side note: to prevent SQL injections I suggest you to perform an int cast on both $_POST['id'] and $_POST['start'], assuming they should be both numeric values:

$start = (int) $_POST['start'];
$id = (int) $_POST['id'];
于 2013-04-17T16:27:55.027 回答
0

This is your mistake

var st = 6;// start position...

st should be 0. In your case you have LIMIT 6, 6. I am guessing you want LIMIT 0, 6

于 2013-04-17T16:27:56.637 回答