search result error message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

The below mentioned code works fine. Connects to the database, fetches the
result, and displays neatly in a table. If there is no data then it jumps to
the if condition and displays the error message. BUT if the 'if' condition
is running and no data is present the Table headings and the bottm of empty
table is still displayed above the error message. Can you please check and
share with me as in where exactly the logic is wrong.

---------- -------------- Code --------------- ------------

<h2>Your favorites search result</h2><div>You are here:  index.htm Home  >
Your favorites</div>		
        <div class="internalContentArea sgtable ">
			<div class="tableHead">Sub-category search result</div>										
					<div>
					<table width='100%' id='table1' cellspacing="0"><thead><tr>
<th scope="col">Shop name</th>

</tr></thead><tbody>
<?php
// database information
   $host = 'xxx';      
   $user = 'xxx';
   $password = 'xxx';
   $dbName = 'xxx';

mysql_connect(localhost,$user,$password);
@mysql_select_db($dbName ) or die( "Sorry But There Seems To Be A Problem
Connecting To The Database");

$query="SELECT * FROM shop";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;

while ($i < $num) {

$shopname=mysql_result($result,$i,"shopname");
echo "
<tr>
<td>$shopname</td>
</tr>";
$i++;
}

?></tbody></table> index.htm < Back to search <div> 
</div>

<? 
if ($num == 0){

echo "
<div>
  <div class='alert'>The search criteria you entered did not generate any
result,  index.htm please try again .</div>
	</div>";

}?>
					
</div>.
-- 
View this message in context: http://www.nabble.com/search-result-error-message-tf2867391.html#a8014018
Sent from the Php - Database mailing list archive at Nabble.com.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux