hosker Posted January 17, 2013 Share Posted January 17, 2013 (edited) I have a query that runs perfectly when I enter it into the SQL tab within my PHP Admin screen, but when I add my PHP to it, it does not display all the values. Here is my code: <?php $i = 1; $position = 1; while($i < 39) { $tournament_sql = "(SELECT * FROM weekly_picks, tournaments_2013, leaderboards_2013 WHERE tournaments_2013.tournament_id = leaderboards_2013.tournament_id AND weekly_picks.tournament_id = leaderboards_2013.tournament_id AND weekly_picks.player_id = leaderboards_2013.player_id AND tournaments_2013.id = '$i') ORDER BY (leaderboards_2013.player_money)DESC"; $tournament_result = mysql_query($tournament_sql); $tournament_row = mysql_fetch_assoc($tournament_result); print "<h2>" . $tournament_row['tournament'] . "</h2>"; print "<div id='picks'><table border=1><tr><th>Position</th><th>Player</th><th>Total</th></tr>"; while ($tournament_row = mysql_fetch_assoc($tournament_result)) { echo "<tr><td>" . $position . "</td><td>" . $tournament_row['user'] . "</td><td>" . $tournament_row['player_money'] . "</td></tr>"; $position++; } print "</table></div>"; $i++; $position = 1; }; ?> Edited January 17, 2013 by hosker Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 17, 2013 Share Posted January 17, 2013 Try checking for MySQL errors. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2013 Share Posted January 17, 2013 $tournament_row = mysql_fetch_assoc($tournament_result); The first row from each set of data is missing. You are fetching the first row using the above line of code. You need to do a couple of things - 1) Don't put a query inside of a loop. You need to execute ONE query that gets the rows you want in the order that you want them. Then you simply output the data the way you want it when you iterate over the rows. 2) To output the heading, you simply remember the last heading (initialize to a value that won't ever appear in the data, such as a null) and detect when it changes to output the new heading, then save the new heading value as the last heading. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.