Forum Moderators: coopster

Message Too Old, No Replies

Need help with conditional statement

         

m_leefs

12:17 am on Mar 5, 2004 (gmt 0)

10+ Year Member



I'm setting up a glossary database (glos) that can search the database for '$sometext' using a form, and then prints out a list of all the words that match with their respective links. The following code works just fine. But if there are no results, I get just a blank page. I would love to get something like "Sorry but your word is not in the database" plus some extra stuff like another form to submit the new word, etc. I just don't know where or how to put in a logic script for if there are no results, do something else. Thanks for any help you can give a php newbie.

<?
$result = mysql_query(
"select * from glos where $word like '%$sometext%' order by word");
while ($i = mysql_fetch_array($result)){
print <<<END
<a href="/definition.php?word={$i['word']}">{$i['word']}</a><br>\n
END;
}

mysql_close();
?>

Timotheos

12:28 am on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi m_leefs,

We were kinda all ready talking about this today [webmasterworld.com]. So now I know the answer ;-)

$result = mysql_query(
"select * from glos where $word like '%$sometext%' order by word");
if (mysql_num_rows($result)>0) {
while ($i = mysql_fetch_array($result)){
print <<<END
<a href="/definition.php?word={$i['word']}">{$i['word']}</a><br>\n
END;
}
}
else {
print "Sorry my friend";
}

m_leefs

5:45 am on Mar 6, 2004 (gmt 0)

10+ Year Member



Thank you so much Timotheos.
It works great now--and my headache is going away : )