Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with coordinating a table with dynamic rows and columns
    primarykey
    data
    text
    <p>Bear with me here--this may be a bit confusing.</p> <p>I am retrieving two sets of data with SQL. Here's the code, with the query. I'm using Zend Framework.</p> <pre><code>$assignments = $db-&gt;fetchAll("SELECT id,name,class FROM assignments"); foreach($assignments as $a) { $assignmentID = $a['id']; $studentData = $db-&gt;fetchAll( "SELECT student,assignment,status,assignmentID FROM student_assignments WHERE assignmentID='$assignmentID'" ); echo "&lt;th&gt;".$a['name']."&lt;/th&gt;"; foreach($studentData as $s) { $bottom .= "&lt;tr&gt;&lt;td&gt;" . $s['student'] . " " . $s['assignmentID'] . " ".$s['status'] . "&lt;/td&gt;&lt;/tr&gt;"; $i++; } } echo "&lt;/tr&gt;$bottom;"; </code></pre> <p>Here's what the output looks like in the HTML:</p> <pre><code>|Assignment on 07/07/2012| |Assignment on 07/12/2012| |Assignment on 07/15/2012| 117 1 Y 332 1 N 36 1 N 420 1 N 332 1 Y 326 2 N 212 2 N 461 2 N 117 2 N 212 2 N 212 3 N 326 3 N 117 3 Y 420 3 Y </code></pre> <p>Now the top part is working great -- it's dynamically showing each assignment in the database. But I've been trying to figure out a way to get the appropriate data to show under those columns, to no effect. This is the closest I've gotten to making it look somewhat correct.</p> <p>Essentially, the data that has "2" and "3" in the middle should go into the 2nd and 3rd columns, respectively. But this isn't happening because all the data is stored into the $bottom variable, rather than the data for each assignment.</p> <p>Does anyone have any suggestions? This is driving me crazy, and I feel like the solution is staring me in the face.</p> <p>Thanks!</p>
    singulars
    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