Jump to content

Reporting


phatgreenbuds

Recommended Posts

Ok so another hurdle.  Reporting on a database has thrown me for a loop.  Lets say I want to count the number of specific entries and display the count in report. for example:

5 red apples
6 green apples

where there are 5 unique rows that include "red" and "apples" and 6 unigue rows that include "green" and "apples".

I think i know the query part but the output is whats confusing me.

[code]
$result = mysql_query("SELECT count(*) FROM mydb GROUP BY color AND catagory");

$num_rows = mysql_num_rows($result);

//Now how do you display it?

[/code]
Link to comment
https://forums.phpfreaks.com/topic/33499-reporting/
Share on other sites

Here is something. Change table and field names to fit your table
[code]<?php
$table = "items";
// Query database
$sql = "SELECT count(ITEM) AS total, CATAGORY, ITEM, QTY_REQ, STILL_NEEDS FROM ".$table." ";
$sql .= "GROUP BY CATAGORY, ITEM";
  $res = mysql_query($sql);
  $num_rows = mysql_num_rows($res);
if($num_rows > 1){
    while ($rows = mysql_fetch_assoc($res)){
// Print Database Details
echo $rows['total']." -- ".$rows['ITEM']." -- ".$rows['CATAGORY']."<br />";
}
} else {
// Print No data message
print '<strong>NO ITEMS!!</strong>';
}
?>[/code]

I have a table I use for testing the ITEM is the color for your table

Ray
Link to comment
https://forums.phpfreaks.com/topic/33499-reporting/#findComment-156820
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.