I am trying to print a recursive list where every date has a sublist of events ordered by date.
For example on the database I have:
+------+----------+--------+
| date | event_id | post_id|
+------+----------+--------+
|date1 | event1 | post1 |
|date1 | event2 | post2 |
|date1 | event3 | post3 |
|date2 | event4 | post4 |
|date2 | event5 | post5 |
+------+----------+--------+
I need to print
<ul>
<li>date1</li>
<ul>
<li>event1, post1</li>
<li>event2, post2</li>
<li>event3, post3</li>
</ul>
<li>Date 2</li>
<ul>
<li>event4, post4</li>
<li>event5, post5</li>
</ul>
</ul>
how can I print in php the
select date, event_id, post_id from tablename
query in php to have this?
After a while with php and mysql, I do the least I can in mysql, even if it’s often more elegant. Performance of mysql is crap. And even if what you query is fast, it can still slow down another query elsewhere done by another user. So here is a response with the least load on the DB. One query, no grouping. just select your 3 fields, and you can apply this.