Jump to content

[SOLVED] Display Table with some fields from database


herghost

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

  

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.