Jump to content

Group and count results per day


knox203

Recommended Posts

Hey everyone, I have a query that grabs orders out of our database by a Monday through Sunday period. I'm wondering how can I get a count of all the orders per day without modifying my query? Can this be done with PHP?

 

Here's my query:

<?php
$ic = "	SELECT	id, dts, driver, date, job, pay_period, round(base,2) as base_round
	FROM 	$databasename.$databasetable 
	WHERE 	driver = '$username' AND left(dts, 15) = '$dts_select' AND pay_period = '".$_POST['pay_period']."'"; ?>

 

Thanks!

- Adam

Link to comment
https://forums.phpfreaks.com/topic/109036-group-and-count-results-per-day/
Share on other sites

I'm guessing you're selecting a whole week's data? You could include this in your mysql_fetch loop

 

 

while ( $row = mysql_fetch_assoc( $result ) ) {
    # Incase E_ALL is on
    if ( !isset( $count[ $row['date'] ] ) )
        $count[ $row['date'] ] = 0;
    $count[ $row['date'] ]++;
}

print_r($count)

 

There's probably an easier way, though.

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.