...

View Full Version : the IF statement?



cooper3000
01-12-2006, 01:20 PM
I have used the following code to do 2 things:

1: if no data is entered into my search boxes then a reply is printed.
2: if correct data is entered into my serach it returns the result.

I would also like it to return a reply if no data is found by the search, I have tried alsorts but can't seem to combine the three without having the reply show on both the result data and the not found data.

$Query = "SELECT * from $TableName where category LIKE '%$_GET[category1]%'";
$Result = mysql_db_query ($DBName, $Query, $Link);
if (empty($_GET['category1']) and empty ($_GET['business1'])) {
print ("<BR>\n");
print ("Sorry, no data found<BR>\n");
} else while ($Row = mysql_fetch_array ($Result)) {
print ("<BR>\n");
print ("<b>$Row</b><BR>\n");
print ("$Row[addressline1], $Row[addressline2] $Row[village]<BR>\n");
print (ucfirst("$Row[town]<BR>\n"));
print (ucfirst("$Row[county]<BR>\n"));
print (strtoupper("$Row[postcode]<BR>\n"));
print ("<b>T:</b> $Row[telephone]<BR>\n");
print ("<b>F:</b> $Row[fax]<BR>\n");
print ("<b>E:</b> <a href=mailto:$Row[email]>$Row[email]</a><BR>\n");
print ("<a target=_blank href=http://$Row[website]>$Row[website]</a><BR>\n");
print ("<b>Category:</b> $Row[category]<BR>\n");
print ("<b>Features:</b> $Row[feature1] $Row[feature2]<BR>\n");
print ("----------------------------------------------------------------\n");
}


[B]Please if you can help get in touch

Cooper
:confused:

davehaz
01-12-2006, 01:46 PM
have you tried adding this to your script?


$rows=mysql_num_rows();
if(!$rows){ echo "No Results Found, Please Enter Another Search String";}
else {
The rest of your script


}

degsy
01-12-2006, 01:46 PM
Use elseif
http://uk2.php.net/elseif

Also when posting code in the forums it's handy to put it in PHP or CODE tags.



<?php
echo 'This is php code';
?>

cooper3000
01-12-2006, 02:10 PM
Warning: Wrong parameter count for mysql_num_rows() in

I keep getting this erroe message ... any ideas why?

Cheers

Cooper

degsy
01-12-2006, 02:19 PM
http://uk2.php.net/mysql_num_rows

You need to query something


$rows=mysql_num_rows($Result);

davehaz
01-12-2006, 02:22 PM
sorry, I was in a hurry and forgot to put that in.

cooper3000
01-12-2006, 02:56 PM
Thanks Guys, all sorted now.

Many Thanks

Cooper
:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum