HCProfessionals Posted May 1, 2013 Share Posted May 1, 2013 Everything works great, except the part where I am trying to get the mysql_num_rows for each category - $jobsc_row['job_category'] <?php $jobsc_query = "SELECT j.id, j.jobc_name, c.job_category FROM site_jobscats AS j LEFT JOIN site_jobs AS c ON j.id=c.job_category WHERE jobc_active='1'"; $jobsc_result = mysql_query($jobsc_query) or die("There was a problem with the SQL query: " . mysql_error()); while ($jobsc_row = mysql_fetch_array($jobsc_result)) { $jobcatid = $jobsc_row['id']; $jobcatname = $jobsc_row['jobc_name']; $jobcatcount = mysql_num_rows($jobsc_row['job_category']); echo "<li><a href=\"jobs.php?cat=$jobcatid\">$jobcatname [$jobcatcount]</a></li>"; } ?> Quote Link to comment Share on other sites More sharing options...
oaass Posted May 1, 2013 Share Posted May 1, 2013 That is not how mysql_num_rows() works. It returns numbers of records returned from the database. To count array items you must use count() or sizeof() Quote Link to comment Share on other sites More sharing options...
Solution trq Posted May 1, 2013 Solution Share Posted May 1, 2013 No kidding. mysql_num_rows returns the number of rows contained within a result resource and expects to be passed a result resource. Your result resource is in $jobsc_result but that won't help you. What your trying to do is find the size of a simple array. Replace mysql_num_rows() with count(). And please, turn error reporting on when writing code!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.