Jump to content


Photo

No results when search


  • Please log in to reply
2 replies to this topic

#1 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 09 March 2006 - 03:02 AM

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
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>";
   
}



Im thinking I would need something like

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


will this work?



#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 March 2006 - 09:10 PM

A couple of ways to do this

1.

$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";

}


2.

$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";

}



If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 11 March 2006 - 12:04 AM

Thanks, so I had the right idea just a little off in the sintax! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users