Question

I am trying to make a social networking website and I am programming for it. But I encountered a problem in it. When user try to update status for 1st time, it is not shown,then when he try to update next status then 1st one is shown but not the second one.Please fix it...

Here are my code.

Table code for status updates.

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

Update status code

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

($l refers to login name)

Show updates code

$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>";
}
}
Was it helpful?

Solution

$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>";
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top