php mysql中的运行时错误

时间:2013-06-08 08:37:41

标签: php mysql social

我正在尝试创建一个社交网站,我正在为它编程。但我遇到了一个问题。当用户尝试第一次更新状态时,它不显示,然后当他尝试更新下一个状态时,显示第一个但不显示第二个。请修复它...

这是我的代码。

状态更新的表格代码。

CREATE TABLE updates (
id int unsigned NOT NULL auto_increment PRIMARY KEY,
login varchar(50) NOT NULL,
status text NOT NULL,
time timestamp NOT NULL
);

更新状态代码

mysql_query("INSERT INTO updates (login, status) VALUES ('$l','$status')");

($ l指登录名)

显示更新代码

$sql = mysql_query("select * from status where login='$l' order by id DESC");
$row = mysql_fetch_array($sql);
echo "<b>Status Updates</b><br>";
if(mysql_num_rows($sql) == 0)
echo "No Status updates till now";
else
{
while($row = mysql_fetch_array($sql))
{
echo $row['login']. "<br>";
echo $row['status']. "  <br>";
}
}

1 个答案:

答案 0 :(得分:0)

$row = mysql_fetch_array($sql);  // Fetches the row you want and then discards it
echo "<b>Status Updates</b><br>";
if(mysql_num_rows($sql) == 0)
    echo "No Status updates till now";
else
{
    while($row = mysql_fetch_array($sql))  // you've already discarded the status
    {                                      //    you want at this point, so it's 
        echo $row['login']. "<br>";        //    displaying the rest of the result set
        echo $row['status']. "  <br>";
    }
}