-9

在我的Ajax 聊天脚本中,我收到了以下警告:

Warning: mysql_fetch_array() expects parameter 1 to be resource,
boolean given in /home/mychat/public_html/c/listChats.php on line 7

第 7 行:

while($row = mysql_fetch_array($sql)){

listChats.php:

<?php 
$chats = "";

include_once("scripts/connect_db.php");

$sql = mysql_query("SELECT * FROM (
    SELECT * FROM chatBox order by id DESC LIMIT 20
) TMP ORDER BY tmp.id ASC");

while($row = mysql_fetch_array($sql)){
    $chat = $row['chatBody'];
    $username = $row['username'];
    $chats = '<p><span id="un">' . $username . ':</span> ' . $chat . '</p>';
    echo "$chats";
}
?>
4

2 回答 2

1

您的查询语法错误

尝试这个

$sql = mysql_query("SELECT *,(

    SELECT * FROM chatBox order by id DESC LIMIT 20

) as data FROM TMP ORDER BY tmp.id ASC");

更新的查询

select *,(select username from chatBox where id=".$_SESSION['userid'].") from chatBody where user_id=".$_SESSION['userid']
于 2012-12-24T06:30:29.347 回答
0

我认为您使用了错误的表名。

尝试这个

$sql = mysql_query("SELECT *,(

    SELECT * FROM chatBox order by id DESC LIMIT 20

) as data FROM TMP ORDER BY TMP.id ASC");

如果你的桌子是TMP那么使用TMP.id如果它是tmp那么使用tmp.id

于 2012-12-24T06:52:30.617 回答