...

View Full Version : problem with else statement



boeing747fp
11-28-2003, 03:58 PM
i have this search engine and i want it to display the words "Search Returned No Results" if $row is empty..... but i did it and it posts "Search Returned No Results" even if it did return results.... i also tried else if and it didnt work
-----------------

<?php
$q = $_GET['q'];
if(isset($q)){
$aa = mysql_connect("localhost", "root", "");
$db = mysql_select_db("whmx_store",$aa);
$sql_select = "SELECT * FROM cds WHERE keywords LIKE '%$q%' ORDER BY artist ASC";
$result = mysql_query($sql_select) or die ("Queryproblem: " . mysql_error());

while ($row = mysql_fetch_array($result)) {
print "<table width='100%' border='0' cellspacing='0'>";
print "<tr>";
print "<td width='10%' rowspan='3'>&nbsp;<img src='$row[2]' width='44' height='44'>&nbsp;";
print "<td width='80%' align='left'><font face='arial' size='2' color='navy'><b><a href='$row[4]'>$row[1] - <em>$row[0]</a></em></b></font>";
print "<td width=10%' align='center'><a href='$row[3]'><img src='34y.gif' border='0'></a></td>";
print "</tr>";
print "<tr>";
print "<td align='left'>";
printf ("%.145s...", "<font face='arial' size='1' color='navy'>$row[6]</font>");
print "</td>";
print "</tr>";
print "<tr>";
print "<td align='left'>";
printf ("%.130s...", "<font face='arial' color='blue' size='1'><a href='$row[4]'>http://store.whmx.com/$row[4]</a></font>");
print "</td>";
print "</tr>";
print "</table><hr color='orange' width='97%'>";
}

}
if(empty($row)){
echo "<font face='arial' size='3' color='navy'><center><b>No Results found for your search:</b> <em>$q</em></center></font>";
}
?>

Nightfire
11-28-2003, 04:13 PM
Try this


<?php
$q = $_GET['q'];
if(isset($q)){
$aa = mysql_connect("localhost", "root", "");
$db = mysql_select_db("whmx_store",$aa);
$sql_select = "SELECT * FROM cds WHERE keywords LIKE '%$q%' ORDER BY artist ASC";
$result = mysql_query($sql_select) or die ("Queryproblem: " . mysql_error());

$rowsfound = mysql_num_rows($result);

if($rowsfound > 0){
while ($row = mysql_fetch_array($result)) {
print "<table width='100%' border='0' cellspacing='0'>";
print "<tr>";
print "<td width='10%' rowspan='3'>&nbsp;<img src='$row[2]' width='44' height='44'>&nbsp;";
print "<td width='80%' align='left'><font face='arial' size='2' color='navy'><b><a href='$row[4]'>$row[1] - <em>$row[0]</a></em></b></font>";
print "<td width=10%' align='center'><a href='$row[3]'><img src='34y.gif' border='0'></a></td>";
print "</tr>";
print "<tr>";
print "<td align='left'>";
printf ("%.145s...", "<font face='arial' size='1' color='navy'>$row[6]</font>");
print "</td>";
print "</tr>";
print "<tr>";
print "<td align='left'>";
printf ("%.130s...", "<font face='arial' color='blue' size='1'><a href='$row[4]'>http://store.whmx.com/$row[4]</a></font>");
print "</td>";
print "</tr>";
print "</table><hr color='orange' width='97%'>";
}
}else{
echo "<font face='arial' size='3' color='navy'><center><b>No Results found for your search:</b> <em>$q</em></center></font>";
}
}
?>

boeing747fp
11-28-2003, 04:28 PM
thanks... that worked



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum