SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Ranking players

  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ranking players

    Hi

    I've been twisting my brain for too long. I'm quite new to php and I'm creating a web site for my monthly poker happenings. What I'd like to do is this:

    After we played a tournament I want to rank the players according to when they where knocked out. My latest code is this:

    PHP Code:
    echo "<form action='rank_tourney.php' method='post'><p>";
        echo 
    "<table border = '1' width = '50'>
        <tr><th>Rank</th><th>Player</th></tr>"
    ;
        for (
    $i=1$i<=8$i++){
            echo 
    '<tr><td><center>'$i .'.</center></td><td>';
            echo  
    "<select name='player'>
            <option value=''>Player</option>"
    ;    
            
    $result mysql_query("SELECT username FROM user ORDER BY username");    
            while (
    $row mysql_fetch_array($result)) {
                echo 
    "<option value='{$row['username']}'>{$row['username']}</option>";
            };
            echo 
    "</td></tr>";

        }
        echo 
    "</select></p>
        </table><br />
        <input type='submit' name='submit' value='Submit' />
        </form>"

    I wouldn't pay to much attention to the code, but it should give you and idea of what I'm thinking of. I collect the players from my DB.
    The problem is to "attach" the rank to the player after hitting 'submit'. I need to send the following information to the DB: the rank of each player in that particular tournament (I get the tournament id from the URL ($_GET)).
    My guess is that this shouldn't be to hard to do, but I'm been stuck for two weeks now. Hopefully someone at Sitepoint is able to give me directions. Apologies for my English.

    -
    peddy

  2. #2
    SitePoint Zealot chrisdpucci's Avatar
    Join Date
    Dec 2006
    Location
    On the internets
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It shouldn't be hard at all but I don't see any ranking information in the code you posted. Where is that data coming from? Are you already storing rankings in your database? What code do you have so far? Provide a little more info and I'll see what I can knock out for you.

  3. #3
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quick response.

    Actually, the

    PHP Code:
    for ($i=1$i<=8$i++) 
    lists the ranks (as I always will have eight players). Then

    PHP Code:
    while ($row mysql_fetch_array($result)) {
                echo 
    "<option value='{$row['username']}'>{$row['username']}</option>";
            }; 
    creates a drop-down menu where I can select which player placed as number one to eight ($i).
    What I need is something to connect $i (rank) to the drop-down menu (player). This is just how I've been thinking. If there is a other (better) way, I'm open minded

    -
    peddy

  4. #4
    SitePoint Zealot chrisdpucci's Avatar
    Join Date
    Dec 2006
    Location
    On the internets
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still don't see how your for loop is any kind of real ranking information. It's a simple loop that will list your players in order by your sql statement. Usually there would be a field in your database that holds the ranking data. If you need to order them by their ranking and need a form to do that then you are going the wrong direction.

    First step is add a rank field in your database. Then you'll want to make a form where you can assign a rank to each player. Maybe I'm not really grasping exactly what you are wanting to do though.

  5. #5
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I think I'm complicating the whole thing.

    After we've played a tournament I want to enter the results (think that explains it better than "ranking players").

    So I print a table with 8 lines ($i) and a drop-down menu on each line. The player I choose on line 1 placed first in that tournament and so on. I have a field in my DB for storing the rank/result. My problem is I need a way to "collect" the data for what player finished in x place in that tournament after I hit the "Submit" button.

    Thanks for your patience.

    -
    peddy


Bookmarks

Posting Permissions

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