Discussion:
Split/Group date together.
Karl-Arne Gjersøyen
2013-07-18 13:43:01 UTC
Permalink
Hello again.
In my program I have this:

mysql> SELECT * FROM transportdokument WHERE dato >= '16/7/2013' AND dato
<= '18/7/2013';

This list all reccrds for 3 days. I need a way to split it up for every day
even when the requst is as above and don't know in what way I can do it.

I like to have all records for day 16 in one table in PHP/HTML and all
records for day 17 in another table.
i.e, Day 16 have 5 rows and day 17th and 18th have 7 and 8 rows.

I hope for your help and advice to do also this correct.

Thank you for your time and effort!

Karl
Bastien Koert
2013-07-18 14:01:34 UTC
Permalink
Normally, what I do here is handle that in the loop to display the records
... so start by adding an order by clause to keep the dates together

SELECT * FROM transportdokument WHERE dato >= '16/7/2013' AND dato
<= '18/7/2013' order by dato

$prior_date = "";

$sHTML = "<table>";

while($rows = mysql_fetch_array($result)){

if ($prior_date != $rows['dato']){
if($open_table){
$sHTML .= "</table><table>";
$prior_date = $rows['dato'];
}
}
$sHTML .= "<tr>";
$sHTML .= "<td>". $rows['dato'] . "</td>";
$sHTML .= "<td>". $rows['some_field'] . "</td>";
$sHTML .= "<td>". $rows['another_field'] . "</td>";
$sHTML .= "<td>". $rows['third_field'] . "</td>";
$sHTML .= "</tr>";
}

$sHTML .= "</table>";
Post by Karl-Arne Gjersøyen
Hello again.
mysql> SELECT * FROM transportdokument WHERE dato >= '16/7/2013' AND dato
<= '18/7/2013';
This list all reccrds for 3 days. I need a way to split it up for every day
even when the requst is as above and don't know in what way I can do it.
I like to have all records for day 16 in one table in PHP/HTML and all
records for day 17 in another table.
i.e, Day 16 have 5 rows and day 17th and 18th have 7 and 8 rows.
I hope for your help and advice to do also this correct.
Thank you for your time and effort!
Karl
--
Bastien

Cat, the other other white meat
Larry Garfield
2013-07-18 15:14:12 UTC
Permalink
If I understand you correctly, I call what you're trying to do "PHP
group by", and did a write up on it a few years back:

http://www.garfieldtech.com/blog/php-group-by-with-arrays

--Larry Garfield
Post by Karl-Arne Gjersøyen
Hello again.
mysql> SELECT * FROM transportdokument WHERE dato >= '16/7/2013' AND dato
<= '18/7/2013';
This list all reccrds for 3 days. I need a way to split it up for every day
even when the requst is as above and don't know in what way I can do it.
I like to have all records for day 16 in one table in PHP/HTML and all
records for day 17 in another table.
i.e, Day 16 have 5 rows and day 17th and 18th have 7 and 8 rows.
I hope for your help and advice to do also this correct.
Thank you for your time and effort!
Karl
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...