PDA

View Full Version : No Records To Display


thepocketgeek
08-07-2006, 03:17 PM
Ok. Here is my problem. I am setting up your basic record retreival using a mySQL database and PHP. If there are no records that match the query, I would like to display a simple message indicating so.

Here is the code I was working with so far:

This is the query being used:

$result = mysql_query("SELECT * FROM `listings` WHERE `job_corp` = '1' AND 'job_satus = 'active'");


This is the section of code I am using to display.


if (isset('$result')){
$row = mysql_fetch_array($result);
echo ("<p><table width=\"800\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">
<tr>
<td bgcolor=\"#F3F1E2\"><div align=\"center\">Job Title </div></td>
<td bgcolor=\"#F3F1E2\"><div align=\"center\">Job Location </div></td>
<td bgcolor=\"#F3F1E2\"><div align=\"center\">Job Description </div></td>
<td bgcolor=\"#F3F1E2\"><div align=\"center\">Job Status </div></td>
<td bgcolor=\"#F3F1E2\"><div align=\"center\">Job code </div></td>
<td bgcolor=\"#F3F1E2\"><div align=\"center\">Job Open </div></td>
<td bgcolor=\"#F3F1E2\"><div align=\"center\">Job Close </div></td>
</tr>
<tr>
<td width=\"14%\" align=\"center\" valign=\"top\">".$row['job_title']."</td>
<td width=\"14%\" align=\"center\" valign=\"top\">".$row['job_location']."</td>
<td width=\"20%\" align=\"center\" valign=\"top\">".$row['job_description']."</td>
<td width=\"8%\" align=\"center\" valign=\"top\">".$row['job_status']."</td>
<td width=\"14%\" align=\"center\" valign=\"top\">".$row['job_code']."</td>
<td width=\"14%\" align=\"center\" valign=\"top\">".$row['job_open']."</td>
<td width=\"14%\" align=\"center\" valign=\"top\">".$row['job_close']."</td>
</tr>
</table></p>
"); }else if (!isset($result)) {
echo ('There are no Current Job Openings at this time.');
}

Basically what I would like to do is this:

if (query returns records)
echo query results
else
echo sorry, no results for you!

Any suggestions?

Brandoe85
08-07-2006, 03:26 PM
Hi,

Use mysql_num_rows();
http://us3.php.net/mysql_num_rows

Good luck;