Jump to content

Count?


mikenl

Recommended Posts

I need to know the number of categories (cat_id).

 

I have tried to use COUNT but cannot get it to work... Please assist if you know how to do it?

 

$lookup = "
    
SELECT 

prostorage_roh_eingang.id as subcat_id, 
prostorage_roh_eingang.charge, 
prostorage_roh_eingang.lieferant, 
prostorage_roh_eingang.qty_kg,
prostorage_roh_eingang.qty_l,
prostorage_charge.charge as cat_id,
prostorage_charge.date,
prostorage_roh.id,
prostorage_roh.name,
prostorage_roh.abb
    
FROM 

prostorage_charge JOIN prostorage_roh_eingang JOIN prostorage_roh
    
ON

prostorage_roh_eingang.charge = prostorage_charge.charge

WHERE 

prostorage_roh_eingang.id = prostorage_roh.id

AND

prostorage_charge.date < '$today'

ORDER BY prostorage_roh_eingang.charge

";

  $query = mysql_query($lookup);
  
  $num_rows = mysql_num_rows($query);  

$current_catid = '';

while ($row = mysql_fetch_assoc($query)) {

    if ($current_catid != $row['cat_id']) {

// Close previous subcat table if not 1st time through
      if ($current_catid != '') { echo '</div>'; }

      //First entry for this category - show category header
      $current_catid = $row['cat_id'];

} // End if 

    //Display the subcat data

} //End while loop

Link to comment
https://forums.phpfreaks.com/topic/63705-count/
Share on other sites

Hi, I want to know the number of found rows for prostorage_charge.charge as cat_id, see the code.

 

So, not the total number of rows returned, that is not the problem. Only the number of rows that were found for prostorage_charge.charge as cat_id.

 

I need this because there are apparently 4 categories (prostorage_charge.charge as cat_id) returned by this query, and 5 subcategories (prostorage_roh_eingang.id as subcat_id).

 

I hope this makes it a bit clearer?

Link to comment
https://forums.phpfreaks.com/topic/63705-count/#findComment-320371
Share on other sites

  • 2 weeks later...

try this

SELECT count(prostorage_roh_eingang.id) as cnt_subcat_id,count(prostorage_charge.charge) as cnt_cat_id FROM prostorage_charge,prostorage_roh_eingang,prostorage_roh where prostorage_roh_eingang.charge = prostorage_charge.charge AND prostorage_roh_eingang.id = prostorage_roh.id AND prostorage_charge.date < '$today' ORDER BY prostorage_roh_eingang.charge;

I didn't check what I did

 

 

Link to comment
https://forums.phpfreaks.com/topic/63705-count/#findComment-329586
Share on other sites

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.