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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/277480-mysql_num_rows-help/ 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() Link to comment https://forums.phpfreaks.com/topic/277480-mysql_num_rows-help/#findComment-1427435 Share on other sites More sharing options...
trq Posted May 1, 2013 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!!! Link to comment https://forums.phpfreaks.com/topic/277480-mysql_num_rows-help/#findComment-1427437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.