Jump to content

PHP MySQL Issue


hosker

Recommended Posts

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 by hosker
Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.