Jump to content

Archived

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

me1000

No results when search

Recommended Posts

ok Im using a simple search script that I wrote but when there was no results returning It shows up blank and I want to change that.

heres my script
[code]while($r=mysql_fetch_array($result))
{    

// change page type #'s to words
$page_type = $r["PAGE_TYPE"];
$new_type = "";

if ($page_type == 1) {
$new_type = "Home";
} else if ($page_type == 2) {
$new_type = "Series";
} else if ($page_type == 3) {
$new_type = "Movies";
} else if ($page_type == 4) {
$new_type = "Special Features";
} else if ($page_type == 5) {
$new_type = "Gaming";
} else {
$new_type = "Unknown";
}

  
   //modify these to match your mysql table columns
  
   $title=$r["PAGE_TITLE"];
   $message=$r["PAGE_CONTENT"];
   $id=$r["ID"];
   $link = '<a href ="index.php?page_id='.$id.'">'.$new_type.': '.$title.'</a>';
   $text_output = strip_tags($message, '');
   $search_results = substr($text_output, 0, 200);
  
   //display the data
  
   echo "$link <br> $search_results ... <br><hr>";
  
}[/code]



Im thinking I would need something like

if ($r < 1) {
$show_results2 }
else {
echo "$link <br> $search_results ... <br><hr>";}


will this work?

Share this post


Link to post
Share on other sites
A couple of ways to do this

1.

[code]
$result = mysql_query (" SELECT blah ...... ");

       // get count of rows returned by query
if (mysql_num_rows($result) > 0) {

      while ($r = mysql_fetch_array($result)) {
          // output row data
      }
}
else {

       echo "No records found";

}
[/code]


2.

[code]$result = mysql_query (" SELECT blah ...... ");

        // try to get first row
if ($r = mysql_fetch_array($result)) {

       do {
            // output row data
       } while ($r = mysql_fetch_array($result));

}
else {

       echo "No records found";

}[/code]

Share this post


Link to post
Share on other sites
Thanks, so I had the right idea just a little off in the sintax! :)

Share this post


Link to post
Share on other sites

×

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.