...

View Full Version : displaying results



markman641
08-31-2011, 05:43 AM
Okay, I've got a question. I have the following code:


<center><table border="1">
<tr>
<th>Place</th>
<th>Username</th>
<th>Offers</th>
<th>Prize</th>
</tr>
<?
$get_name = mysql_query("SELECT `username`, `offerscompleted` from `members` WHERE `offerscompleted` > 1 ORDER by offerscompleted desc LIMIT 0,5");
while($namerow = mysql_fetch_array($get_name)) {
$offcomplete = $namerow["offerscompleted"];
$username123 = $namerow["username"];
?>
<tr>
<td>1</td>
<td><?=$username123?></td>
<td><?=$offcomplete?></td>
<td> $25 giftcard </td>
</tr>
<? }?>
</table> </center>


Now... how would I make it so for the PLACE and REWARD column, its different in every row? so its like

1st-----offers-----username--$25 Giftcard
2nd------offers---username---$5 giftcard
ect. understand?

Old Pedant
08-31-2011, 08:06 PM
Where will you get the amounts of the gift cards from?

From another DB table or just from a PHP array?

markman641
08-31-2011, 10:06 PM
Where will you get the amounts of the gift cards from?

From another DB table or just from a PHP array?

just from what i type in.

Old Pedant
08-31-2011, 10:45 PM
Remembering, again, that I'm not a PHP person:


table border="1">
<tr><th>Place</th><th>Username</th><th>Offers</th><th>Prize</th></tr>
<?php
$prizes = array( 50, 25, 15, 10, 5 ); // 5 prizes, in decreasing values of your choice
$get_name = mysql_query("SELECT `username`, `offerscompleted` from `members` "
. " WHERE `offerscompleted` > 1 ORDER by offerscompleted desc LIMIT 0,5");
$prizenum = 0;
while( $namerow = mysql_fetch_array($get_name) )
{
$offcomplete = $namerow["offerscompleted"];
$username123 = $namerow["username"];
$prize = $prizes[$prizenum];
++$prizenum;
?>
<tr>
<td><?=$prizenum?></td>
<td><?=$username123?></td>
<td><?=$offcomplete?></td>
<td>$<?=$prize?> giftcard</td>
</tr>
<? }?>
</table>

Sneaky how you can use $prizenum from 0 to 4 to pick out the prize and then use it from 1 to 5 as the placement number.

Incidentally, this is 100% a PHP question. Has nothing to do with MySQL, so really in the wrong forum. Oh, well.

markman641
09-01-2011, 01:51 AM
Thank you!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum