Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning multiple rows per row (in Zend Framework)
    primarykey
    data
    text
    <p>I have a MySQL database containing these tables:</p> <pre><code>sessions -------- sessionid (INT) [courseid (INT)] [locationid (INT)] [comment (TEXT)] dates ----- dateid (INT) sessionid (INT) date (DATE) courses ------- ... locations --------- ... </code></pre> <p>Each session has a unique sessionid, and each date has a unique dateid. But dates don't necessarily have a unique sessionid, as a session can span over a variable number of dates (not necessarily consecutive).</p> <p>Selecting each full row is simply a matter of joining the tables on the sessionid. However, I'm looking for a way to return a rowset for a particular courseid, where each row in that rowset represents a location, and contains another rowset, each containing single session, which in turn contains another rowset, which contains all of the dates for that session:</p> <pre><code>course location sesssion date date session date date date location ... </code></pre> <p>This is because I'm using querying this database from PHP using Zend Framework, which has a great interface for manipulating rows and rowsets in an object-oriented manner.</p> <p>Ultimately, I'm trying to output a 'schedule' to the view, organized first by course, then location, then date. Ideally, I'd be able iterate over each row as a location, and then for each location, iterate over each session, and then for each session, iterate over each date.</p> <p>I'm thinking of doing this by querying for all the locations, sessions, and dates separately. Then, I'd convert each rowset into an array, and add each sessions array as a member of a locations array, and add each dates array as a member of a sessions array.</p> <p>This, however, feels very kludgy, and doesn't provide me with the ability to handle the rows in an object-oriented manner.</p> <p>I was wondering if there was either:</p> <p>a) a better table schema for representing this data;</p> <p>b) an sql query which i'm not aware of;</p> <p>c) a method in Zend_Db that allows me to assign a rowset to a rowset</p> <p>Please let me know if I haven't been clear anywhere, and thanks in advance.</p> <p>(Crossing my fingers that this doesn't end up on the daily wtf...)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload