I have a database with three tables for a football pool website. The three tables (with fields in parenthesis)...
-USERS (userid, username, firstname, lastname)
-TEAMS (teamid, teamname)
-PICKS (teamid, userid, week#, winner)
Anyway, I know how to have people submit their picks and whatnot, but as far as retrieving the data and displaying it how I want, I am having trouble. Look at the following website to see how my output looks right now...
http://gdoot.com/examplestandings.php
In the pool, users pick 4 winners each week. In the example, Gary has made his Week 2 picks already and I would like that 2nd set of 4 picks to be listed under Week 2. But as you can see, because of my current code, it's wrapping underneath his name field in the HTML table.
This is the code I currently have. Assuming this is enough information, any idea how I can change the code so that each subsequent set of 4 picks for each specific user appears under the next week?
<?php
$user_set = mysql_query("SELECT * FROM users", $connection);
if (!$user_set) {
die("Database query failed: " . mysql_error());
}
while ($users = mysql_fetch_array($user_set)) {
echo "<tr><td class='name' rowspan='4'>{$users["firstname"]}" . " " . "{$users["lastname"]}</td>";
$pick_set = mysql_query("SELECT teamname FROM teams, picks WHERE picks.userid = {$users["userid"]} and picks.teamid = teams.teamid", $connection);
if (!$pick_set) {
die("Database query failed: " . mysql_error());
}
while ($picks = mysql_fetch_array($pick_set)) {
echo "<td class='pick' rowspan='1'>{$picks["teamname"]}</td></t...
}
echo "</tr>";
}
?>
</tr>
</table>
</div>
Tags: