while problem

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!

Moderator: General Moderators

Post Reply
User avatar
skateis2s
Forum Commoner
Posts: 37
Joined: Fri Aug 08, 2003 7:22 am
Location: colorado

while problem

Post by skateis2s »

Okay, I made a search form...

while($r=mysql_fetch_array($result)) {
$blah=$r["name"];
echo $blah;
echo "<br>";
}



that code works when you hit search, but when I put



while($r=mysql_fetch_array($result)) {
$blah=$r["name"];
echo $blah;
echo "<br>";
} else {
echo "No search results.";
}


it gives me on error and says parse error on the line with

} else {


help please ! thankyou
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Well, it's not an if statement, so what you need to do is make an if checking if the search variable is set, so if your search variable was $search you do somethin like

Code: Select all

<?php
if (isset($search)) {
while($r=mysql_fetch_array($result)) { 
$blah=$r["name"]; 
echo $blah; 
echo "<br>";
}
} else { 
echo "No search results."; 
}
?>
Post Reply