Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.