herghost Posted November 1, 2009 Share Posted November 1, 2009 Hi all, I want to display a table like this: position prize user total 1 250 $username $total 2 100 $username $total with the positions going up to 10 and for me to manually fill in the prize for these 10 option. The user and total come from a database called users_stocks and it is meant to display the top 10 users. I know how to display the results using $row[]; but I dont know how I can manually assign the positions and prizes as these are not stored in a database table. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/179821-solved-display-table-with-some-fields-from-database/ Share on other sites More sharing options...
herghost Posted November 1, 2009 Author Share Posted November 1, 2009 oh and to complicate matters further, the username field is in a table called users and not users_stocks! Quote Link to comment https://forums.phpfreaks.com/topic/179821-solved-display-table-with-some-fields-from-database/#findComment-948807 Share on other sites More sharing options...
herghost Posted November 2, 2009 Author Share Posted November 2, 2009 Hi all, Still no luck with this, I cant figure out how to change the prize and position each time anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/179821-solved-display-table-with-some-fields-from-database/#findComment-949293 Share on other sites More sharing options...
cags Posted November 2, 2009 Share Posted November 2, 2009 Examples of what you've tried would probably have helped as it would clarify what exactly your trying to do. $prizes = array(250, 100, 75, 50, 25, 10, 5, 3, 2, 1); $prize_index = 0; $position = 1; // fetch details $result = mysql_query($sql); echo '<table>'; echo '<tr><td>Position</td><td>Prize</td><td>User</td><td>Total</td></tr>'; while($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<td>' . $position++ . '</td>'; echo '<td>' . $prizes[$prize_index++] . '</td>'; echo '<td>' . $row['username'] . '</td>'; echo '<td>' . $row['total'] . '</td>'; echo '</tr>'; } echo '</table>'; Quote Link to comment https://forums.phpfreaks.com/topic/179821-solved-display-table-with-some-fields-from-database/#findComment-949299 Share on other sites More sharing options...
herghost Posted November 2, 2009 Author Share Posted November 2, 2009 Perfect Thanks! <?php $userid = $_SESSION['user_id']; $query = "SELECT * FROM users_stocks ORDER BY users_total DESC LIMIT 0, 10"; $prizes = array(250, 25, 25, 20, 10, 10, 10, 10, 10, 10); $prize_index = 0; $position = 1; // fetch details $result = mysql_query($query); echo '<table>'; echo ' <tr> <th scope="col">Position</th> <th scope="col">Prize</th> <th scope="col">Username</th> <th scope="col">Total</th> </tr>'; while($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<td>' . $position++ . '</td>'; echo '<td>' . $prizes[$prize_index++] . '</td>'; echo '<td>' . $row['username'] . '</td>'; echo '<td>' . $row['users_total'] . '</td>'; echo '</tr>'; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/179821-solved-display-table-with-some-fields-from-database/#findComment-949322 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.