显示一行。 需要在循环中显示它

I am trying to figure out how to use this in a loop. Any help will be appreciated.

$conn = mysql_connect("localhost", "some_user", "password");

if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}

if (!mysql_select_db("some_db")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}

$sql = "SELECT favid FROM  ajaxfavourites";

$result = mysql_query($sql);

if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}



while ($row = mysql_fetch_assoc($result)) {

echo $row["favid"];

}

mysql_free_result($result);

Currently it displays results as:

116677889922

I need them to show them as (the way they are displayed in DB):

1166
7788
9922

PS I am aware that this function is deprecated, I am just trying to fix one of my older sites.

choose One of these ways:

echo $row["favid"]."<br>";

echo $row["favid"]."
";

echo $row["favid"].PHP_EOL;
while ($row = mysql_fetch_assoc($result)) {

echo $row["favid"];
echo "
";

}

You can simply echo the value with '<br/>' or '<p>' like following:

while ($row = mysql_fetch_assoc($result)) {

echo $row["favid"] . '<br/>';

}

OR

while ($row = mysql_fetch_assoc($result)) {

echo '<p>' . $row["favid"] . '</p>';

}

Also you can just put all favid into array and then in another loop, can customize how to show them, like following:

while ($row = mysql_fetch_assoc($result)) {

$ids[] = $row["favid"];

}

foreach($ids AS $idv) {
echo '<p>' . $idv . '</p>';
}