Web Analytics Made Easy -
StatCounter displaying results - CodingForum

Announcement

Collapse
No announcement yet.

displaying results

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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; Aug 31, 2011, 01:57 AM.
    Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

  • #2
    Where will you get the amounts of the gift cards from?

    From another DB table or just from a PHP array?
    Be yourself. No one else is as qualified.

    Comment


    • #3
      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.
      Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

      Comment


      • #4
        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.
        Be yourself. No one else is as qualified.

        Comment


        • #5
          Thank you!!
          Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

          Comment

          Working...
          X