-2

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

这是我的代码。

状态更新的表代码。

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>";
}
}
4

1 回答 1

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>";
    }
}
于 2013-06-08T09:00:45.260 回答