Solved

PHP MySQL Report Output separate HTML table for each "Client"

Posted on 2011-09-22
2
338 Views
Last Modified: 2012-08-14
I have a bill tracking website with a report function in PHP with a drop-down menu of all clients in the database. Currently, the user selects the appropriate client and fires a query that populates the report with that client's information in a nice table format.

I would like to build a similar function, but one that includes ALL clients in the report. The caveat is that I would like each client to be broken out separately, each with their own "table" of billing entries.

Basically, I want to take each "individual client report" and stack them all together into one report.

I can't seem to figure out how to make this work, however. My current query (for the individual report) is:

if ($submit) {
$ccc = $client;
$result = mysql_query("SELECT billing.*, client.* FROM billing, client WHERE billing.client = client.id HAVING billing.client = $ccc ORDER by date asc ");

Open in new window


I can modify that, obviously, to include ALL clients, but they're not broken out and grouped by client. I'm not familiar enough with query modifiers (tried GROUP BY, but no luck), and the script that I'm using doesn't make it any easier.

I'm attaching the entire php page so you can see what I'm working with:
report.php.txt

I'm also attaching a screenshot of what the current (individual) report looks like:  Individual Statement
As well as a graphic of what I am seeking to accomplish:
Individual Statement
Any advice or suggestions would be greatly appreciated!
 
Thanks,
Chris
statement-group.png
0
Comment
Question by:goodie069
2 Comments
 
LVL 17

Accepted Solution

by:
Garry-G earned 500 total points
Comment Utility
Dropping the "having" clause, and adding the client.id before date should do the job ... on your PHP code, make sure the loop remembers the last client id (set to an impossible value before the loop), then when the data fetched has a different client id, finish the last report (if the old client id is something different from the impossible value), then clear sums etc, start a new report. After the loop, if the last client id is nt the impossible value, repeat the finish report block ...
0
 

Author Closing Comment

by:goodie069
Comment Utility
Thanks for pointing me in the right direction! Worked like a charm.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now