Reputation: 3657
Sorry, this is a bit noobish, I cant get a simple while statement to execute while the condition is true and false if no results:
// Select all the rows in the markers table
$query = "SELECT * FROM markers M, professor P
WHERE P.id = M.id;";
if($row = mysql_fetch_array($result)) {
do {
echo $row;
}
while($row = mysql_fetch_array($result));
} else {
die('No results.');
}
The problem I see with this code is $query
is never being called in the mysql_fetch_array()
should this be changed?
Upvotes: 0
Views: 97
Reputation: 224867
PHP while
statements don't have else
s. I believe that's nearly unique to Python. Instead, you can do this:
if($row = mysql_fetch_array($result)) {
do {
echo $row;
} while($row = mysql_fetch_array($result));
} else {
die('No results.');
}
Upvotes: 1
Reputation: 152206
Try with following condition:
if ( mysql_num_rows($result) == 0 ) {
die('No Result');
}
or simplier:
if ( !mysql_num_rows($result) ) {
die('No Result');
}
Upvotes: 1