Jump to content

Please Help Counting Records


lingo5

Recommended Posts

Hi,

 

this is my query here

 

$colname_cats_RS = "-1";
if (isset($_GET['id_categoria'])) {
$colname_cats_RS = $_GET['id_categoria'];
}
mysql_select_db($database_MySQLconnect, $MySQLconnect);
$query_cats_RS = sprintf("SELECT * FROM t_subcategorias WHERE id_categoria = %s", GetSQLValueString($colname_cats_RS, "int"));
$cats_RS = mysql_query($query_cats_RS, $MySQLconnect) or die(mysql_error());
$row_cats_RS = mysql_fetch_assoc($cats_RS);
$totalRows_cats_RS = mysql_num_rows($cats_RS);

 

and this is how I echo the results

 

<?php echo $row_cats_RS['subcategoria_esp']; ?>

 

What I need to do is to display the record count for each subcategory like for example:

 

red (5)

blue(2)

 

etc.... Please help me :-)

Link to comment
https://forums.phpfreaks.com/topic/269388-please-help-counting-records/
Share on other sites

Use a JOIN to link up to which ever table you need to count the values in, then use the sql function COUNT() and the GROUP BY clause to select a list of categories and their counts.

 

You'll have to post the structure of your tables if you need help figuring out how to do the join.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.