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 :-)

Edited by lingo5
Link to comment
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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.