mysql - PHP - Getting num_rows of different ID's without writing new statements? -


basically, i'm coding site has many different categories , want display amount of rows specific id.

so example, have query:

$query= "select job_sec jobs job_sec = ?"; mysqli_num_rows($query); 

i need know how can count rows of id echo rows counted.

i'd results display:

web design: 2,001 jobs

logo design: 5,120 jobs

the job_sec column uses numerical value, easier have text value count rows relating text value , echo them?

i have feeling need use array need efficient method.

any appreciated!

assuming job_sec category , think looking "group by":

$sql= "select job_sec, count(*) c jobs group job_sec"; $r = mysqli_query($sql);  while ($row = mysqli_fetch_assoc($r)) {      echo $row['job_sec'] . ': ' . $row['c'] . ' jobs '; } 

(didn't test , not sure if mysqli syntax correct)


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -