In PHP, a while
statement can't have an else
clause. You need something external to the while
that can tell you if it was executed at least once.
How about something like this?
$total = mysql_num_rows($gamesearched);
if ($total > 0) {
while (($write=mysql_fetch_array($gamesearched)) !== false) {
echo "Found!";
}
} else {
echo "No results";
}
In this case, I've looked up the total number of rows found before I start, but I could also have started by setting a counter to zero and then incrementing it inside the while loop. That would look something like this:
$total = 0;
while (($write=mysql_fetch_array($gamesearched)) !== false) {
$total++;
echo "Found!";
}
if ($total == 0) {
echo "No results";
}
Note that mysql_fetch_array()
returns false
if there are no more rows, so I've updated the while condition for you as well.
All that being said, there are good reasons not to use mysql_*
functions in new code. See this question for more details, and some better alternatives: Why shouldn't I use mysql_* functions in PHP?