Hi,

I've rewritten the code to:

// Sends the Query
$sql_result = mysql_query($sql);
if (!$sql_result) {
   echo "Can't execute $sql " . mysql_error();
   exit;
 }
if (mysql_num_rows($sql_result) == 0) {
 $option_block .= "Sorry, your search has resulted in 0 records. Please try
again. \n";
 }

// organizes data in an orderly manner (ie bulleted area)

while ($row = mysql_fetch_array($sql_result)) {
 $advocateID = $row["advocateID"];
 $esc_fname = $row["FNAME"];
 $esc_lname = $row["LNAME"];
 $esc_firm = $row["FIRM"];
 $esc_city = $row["CITY"];
 $esc_province = $row["PROVINCE"];
 $esc_area = $row["AREA"];
 ....

and it works beautifully! Thanks for pointing me to the clue!

"David Robley" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
> 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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to