Jump to content

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?

Link to comment
https://forums.phpfreaks.com/topic/4495-no-results-when-search/
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]

Link to comment
https://forums.phpfreaks.com/topic/4495-no-results-when-search/#findComment-15912
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.