Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MySql HTML Table Grouping
    text
    copied!<p>I have a problem I can't seem to to wrap my head around. </p> <p>I have a mySQL table setup similar to this: </p> <pre><code>userid date rating1 rating2 1 5/1/2013 5 5 2 5/1/2013 4 4 3 5/1/2013 3 3 2 5/7/2013 5 5 1 5/7/2013 5 5 3 5/7/2013 2 2 </code></pre> <p>I have my php code to query the data:</p> <pre><code>$con=mysqli_connect("localhost","root","password","db"); $result = mysqli_query($con,"SELECT userid,date,rating1,rating2 FROM db"); </code></pre> <p>But when I try and output to a table using:</p> <pre><code>while($row = mysqli_fetch_array($result)) { echo '&lt;table&gt;'; echo '&lt;thead&gt;'; echo '&lt;tr&gt;'; echo '&lt;th&gt;UserID&lt;/th&gt;'; echo '&lt;th&gt;Date&lt;/th&gt;'; echo '&lt;th&gt;First Rating&lt;/th&gt;'; echo '&lt;th&gt;Second Rating&lt;/th&gt;'; echo '&lt;/tr&gt;'; echo '&lt;/thead&gt;'; echo '&lt;tbody&gt;'; echo '&lt;tr&gt;'; echo '&lt;td&gt;'.$row['userid'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['date'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['rating1'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['rating2'].'&lt;/td&gt;'; echo '&lt;/tr&gt;'; echo '&lt;/tbody&gt;'; echo '&lt;/table&gt;'; } </code></pre> <p>It outputs a unique table for each entry. What I need is 1 HTML table per UserID Ex:</p> <pre><code>UserID 1 Date First Rating Second Rating 5/1/2013 5 5 5/7/2013 5 5 UserID 2 Date First Rating Second Rating 5/1/2013 4 4 5/7/2013 5 5 UserID 3 Date First Rating Second Rating 5/1/2013 3 3 5/7/2013 2 2 </code></pre> <p>I am honestly stuck... Thanks in advance for your help!</p>
 

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