Re: Understanding If conditional statements

From: Date: Sun, 14 Apr 2002 23:16:46 +0000
Subject: Re: Understanding If conditional statements
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-92943@lists.php.net to get a copy of this message
In article <20020414225858.8717.qmail@pb1.pair.com>, junkit@lmlweb.com says... > I'm trying to get my code to print out a "sorry - no results" message if > there is no match. I've read the If statement in the PHP manual > (http://www.php.net/manual/ro/control-structures.php#control-structures.if) > > and > > I think my code structure may be wrong.. am I wrong to nest it this way in > the following code? If so, where should I be putting the " if $sql returns 0 > records, then print.." code? > > while ($row = mysql_fetch_array($sql_result)) { > if ($sql_result = 0) { > $option_block .= "Sorry, your search has resulted in 0 records. Please try > again. \n"; > } > else { Firstly, $sql_result insn't the value to check and secondly you should do it before you start the while loop. Do your query to the DB, then check mysql_num_rows. If it is zero, print the error message; otherwise go into the while loop to display your results. -- David Robley Temporary Kiwi! Quod subigo farinam

« previous php.general (#92943) next »