Jump to content

Recommended Posts

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

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>';

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>';
?>

  

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.