Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    displaying results

    Okay, I've got a question. I have the following code:

    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?
    Last edited by markman641; 08-31-2011 at 06:57 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,608
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Where will you get the amounts of the gift cards from?

    From another DB table or just from a PHP array?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Old Pedant View Post
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,608
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Remembering, again, that I'm not a PHP person:
    Code:
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    markman641 (09-01-2011)

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Thank you!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •