I have table entries in my database with structure:
id | card | event | time | day | hm
- > id – is unique ID of each entry.
- > card – is number.
- > event – is number (0, 1, 2, or 3)
- > time – is mysql_timestamp
- > day – is day of month when entry was added (date(“j”, time())
- > hm – some other info…
I want to display all entries for one month in html table.
Now I’m using this simple query:
$sql = "SELECT event, time, day, hm FROM `entries`
WHERE card=$card_t
AND YEAR(time)=$year
AND MONTH(time)=$month
AND event IN (0,1,3)
ORDER BY `time` ASC;";
Conditions of output:
table must have minimum one row for a day (31 rows for January).
if there is no entries for day(1-31) row must be:
if there is only two entries for day row must be:
<tr>
<td>$day_number</td>
<td>$time_of_first_event</td>
<td>$first_event</td>
<td>$time_of_last_event</td>
<td>$last_event</td>
</tr>
if there is more than two entries a day two must be (I will hide second one with jquery later):
<tr>
<td>$day_number</td>
<td>$time_of_first_event</td>
<td>$first_event</td>
<td>$time_of_last_event</td>
<td>$last_event</td>
</tr>
<tr>
<table>
<tr>
<td>$time</td>
<td>$event</td>
</tr>
</table>
</tr>
So it looks like:
| 1 | no entry |
| 2 | no entry |
| 3 | no entry |
| 4 | time_first | event_fisrt | time_last |event_last |
| time2 | event 2 |
| time3 | event 3 |
| 5 | no entry |
...
But all i got now is output of 31 row and if one day have more than it duplicates this day row and displays all rows for this day:
| 1 | no entry |
| 2 | no entry |
| 3 | no entry |
| 4 | time1 event 1 |
| 4 | time2 event 2 |
| 4 | time3 event 3 |
| 5 | no entry |
...
Please help me guys and sorry for mistakes, english is not my native lang.
Use
GROUP_CONCATin sql andexplodeforeach loopIn foreach,