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
Share on other sites

the mysql_num_rows() shows you how many rows it returned...

[code]
$result = mysql_query("SELECT count(color) FROM mydb GROUP BY color AND catagory");
$row = mysql_fetch_array($result);
print_r($row); #depends on your database which field they'll go into  :-)
[/code]
Link to comment
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
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.