Jump to content

Recommended Posts

Please help, when I run this search and enter something in the search thats not in the database, it doesnt reply with "Your query returned 0 results" as it should. I tjust stays blank

 

Here's the section of code in question...

 

if ($search)   // perform search only if a string was entered. 
   { 
    mysql_connect($host, $user, $pass) or die ("Problem connecting to Database"); 

    $srch="%".$search."%";

    $query = "select * from tvads WHERE advert LIKE '$srch' ORDER BY advert, year DESC, details ASC LIMIT 0,30"; 

    $result = mysql_db_query("cookuk_pn", $query); 

    if  ($result) 
    { 

   $count = 1;   

   print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  bordercolor=\"#0000FF\" width=\"900\">";
   print "<tr><td width=\"200\" height=\"30\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Advert / Description</font></b></u></td>";
   print "<td width=\"80\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Year</font></b></u></td>";
   print "<td width=\"200\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Artist</font></b></u></td>";
   print "<td width=\"200\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Track</font></b></u></td>";
   print "<td width=\"80\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Buy Album</font></b></u></td>";
   print "<td width=\"100\" align=\"left\"><u><b><font face=\"arial\" size=\"2\" color=\"#800080\">Download MP3</font></b></u></td></tr>";

        while ($row = mysql_fetch_array($result)) {     // Begin while 


$data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['advert']. "</font><br>";

$data .= "<font face=\"arial\" size=\"1\" color=\"#000080\"><i>" .$row['details']. "</i></font></td>";

$data .= "<td width=\"80\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['year']. "</font></td>";

$data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['artist']. "</font></td>";

$data .= "<td width=\"200\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['track']. "</font></td>";

$data .= "<td width=\"80\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['asin_ref']. "</font></td>";

$data .= "<td width=\"100\" height=\"30\" align=\"left\"><font face=\"arial\" size=\"1\">" .$row['mp3_ref']. "</font></td></tr>";

$count++;

        }                  // end while 
        $data .="</table>"; 
   echo $data;
     } else { echo "problems...."; } 
   } else { echo "Your query returned 0 Results"; } 
?> 

Because the logic is if($search) { , as long as the variable $search has a value, the else{} will not be reached. You need to check how many results the query actually returns in order to determine whether to echo the message or not.

the last else only shows if no search term was entered.  Try this.

$result = mysql_db_query("cookuk_pn", $query);
    if(mysql_num_rows($result)==0) {
        echo "Your query returned 0 Results";
   }

    else if  ($result)
    {
         echo "Your output."
    }

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.