Jump to content

RE: no result


cdoggg94

Recommended Posts

Basically I want this to do do is:

 

if (there is no result found in the query){

echo "nothing for this brand";

}else{

echo this link;

}

 

this is my code...im just confused on what i want the if statement to to ask for.

 

any help would be greatly appreciated :)

 

<?php
$mypro = mysql_query("SELECT * FROM Sheet1 WHERE pro_catagory LIKE '%People%' ORDER BY pro_id DESC");
while($row=mysql_fetch_array($mypro)) {
if(Not sure what to put here){
echo "There are no listings for the brand right now";
}else{
print "- <a href='proList.php?proNumber=".$row['pro_id']."'>".$row['pro_name']."</a><br />";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/262260-re-no-result/
Share on other sites

Use something like this:

$mypro = mysql_query("SELECT * FROM Sheet1 WHERE pro_catagory LIKE '%People%' ORDER BY pro_id DESC");
if(mysql_num_rows($mypro) == 0)
{
   echo "There are no listings for the brand right now";
}
else
{
   while($row = mysql_fetch_array($mypro))
   {
     print "- ".$row['pro_name']."
";
   }
}
?>

 

Don't use * unless you really want to select every column.

You also would want to add some proper error checking because there is a chance mysql_query could return "false" which would error out your program, read - http://www.phpfreaks.com/blog/or-die-must-die

Link to comment
https://forums.phpfreaks.com/topic/262260-re-no-result/#findComment-1344012
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.