By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,874 Members | 646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,874 IT Pros & Developers. It's quick & easy.

If result set is empty print "no records"

P: 155
I've tried to incorporate an IF Statement into the below so that if the query returned nothing - a message saying "There are no jobs currently listed" would be displayed, but for some reason it hasn't worked. Right now it just returns a blank table.

$query="SELECT * FROM $nameid WHERE display_ad='yes' AND submitted > SUBDATE(NOW(), INTERVAL 30 DAY) ORDER BY submitted DESC LIMIT $offset, $rowsPerPage";
$result=mysql_query($query) or die('Error, query failed');

while ($i < $num)
$fdate = explode('-', $date);

<td width="35%"><? echo ("<A HREF='see_job.php?nameid=$nameid&file=$id'>$compan y</A>"); ?></td>

<td width="37%"><? echo "$position"; ?></td>

<td width="16%"><? echo "$city"; ?></td>

<td width="12%"><? echo "$fdate[1]/$fdate[2]/$fdate[0]"; ?></td>

} [/PHP]
Oct 2 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,584
First what is this "mysql_numrows" ? (4th line in the above code)

Then read here please:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $num=mysql_num_rows($result); 
  3. if($num > 0){
  4.     while($row=mysql_fetch_assoc($result)){
  5.     //Print The $row array elements here
  6.     echo $row['MySQL_COLUMN_NAME1'];
  7.     echo $row['MySQL_COLUMN_NAME2'];
  8.     echo $row['MySQL_COLUMN_NAME3'];
  9.     }
  10. }else{
  11. echo 'No-Records';
  12. }
  13. ?>
Oct 2 '07 #2

P: 155
First what is this "mysql_numrows" ?
It's just something I've always used, but I like yours better. Works fine now, thanks!

Oct 2 '07 #3

Expert 100+
P: 1,584
And David, If you ever need anything post back to the forum. Thanks.
Oct 3 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.