PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
what I do if I think I'm going to have multiple rows that I want to loop over is just check if it returned any rows with mysql_num_rows(). If that isn't 0 then do your while loop.
if you are just going to return one row you can use if instead of while
$sql = "SELECT * FROM table WHERE bla = 'no' ORDER BY date ASC LIMIT 1";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$blabla = $row['blabla'];
if($rows = mysql_fetch_assoc($result)){
echo "$blabla";
}else{
echo "No records found";
}
}
$sql = "SELECT * FROM table WHERE bla = 'no' ORDER BY date ASC LIMIT 1";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
$blabla = $row['blabla'];
}
}
else
{
echo 'No Records found';
}
}
you have a while then a for and you dont concatanate the variable and you have the variable in quotes so its not going to eval it. and its easier to use mysql_num_rows to check than an else
$blabla = ""; // I dont use php5 but if you are i think you need to initalize
// the var before concatnating it
$total = mysql_num_rows($result);
if ($total == 0) { echo 'no results found'; die; }
while ($row = mysql_fetch_array($result)){
$blabla .= $row['blabla']; // note the dot
echo $blabla;
that should make your code work and the variable echo