php - Make search output error if no results are found -


i trying make error message appear if when user searches, no results found; having issue getting error message display.

here code:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8" />     <title>php test file</title>     <link href="phptestcss.css" rel="stylesheet" type="text/css" />     <link href="lightbox-style/lightbox.css" rel="stylesheet" type="text/css" media="screen"/>     <script src="js/prototype.js" type="text/javascript"></script>     <script src="js/scriptaculous.js?load=effects,builder" type="text/javascript"></script>     <script src="js/lightbox.js" type="text/javascript"></script> </head>  <body>      <?php include 'header.html'; ?>      <?php      include 'databaseconnect.php';      //- queries table content rows -      $queryselect =  "select thumbnail,image,title homepage title '%".mysql_real_escape_string($_post['search'])."%' ";      //----------------- query table, store content in php variable -----------------     $result = mysql_query($queryselect);      //-------------- store content id  = 1 in array --------------      -------------------     include 'logo.html';     ?>     <div class="searchcontainer">         <form method="post" action="index.php">             <input type="text" class="input" name="search" size="40" placeholder="search...">             <input type="submit" class="button" name="submit" value="search" id="submit" >         </form>     </div>     <?php  $numrows = mysql_num_rows ($result );     if($numrows = 0 , isset($_post['search'])){         echo '<div class="errorcontainer">';         echo '<div class="erroricon">';         echo "!";         echo '</div>';         echo "your search returned no results, try searching website category e.g sports or cars";         echo '</div>';     }      else{          while ($row =mysql_fetch_object ($result)) {              //- main content -              echo '<div class="wrapper">';             ?>              <?php              //--------- post html variables. put php variables -----------------------------               $search = $_post['search' ];               //--------------- if row count not = 0, while there rows content, output html ----------              ?>              <?php             echo '<div class="imagecontainer">';             echo "<a href=\"".$row->image."\" rel=\"lightbox\"><img src=\"".$row->thumbnail."\" width=\"300\" height=\"300\"border=\"0\"/></a>";             echo '<div class="titlecontainer">';             echo "".$row->title."";             echo'</div>';             echo'</div>';             echo'</div>';         }     }      ?>  </body> </html> 

at minute, content displays when search exists, if search doesn't exist - error message have set not display, , unsure why.

you have misplaced following code

 $numrows = mysql_num_rows ($result ); 

should before following line of code

 if($numrows = 0 , isset($_post['search'])){ 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -