/    Sign up×
Community /Pin to ProfileBookmark

competitive ladder system for games

Hi.

I recently became obsessed with web developing, and ever since that, i have been following all kinds of tutorials about html, css, php, mysql and other web related stuff like CMS’s like joomla wordpress and so on…

I choose to write on these forums in hope of guidelines. I dont expect anyone to do my work, but i would love some insight and suggestions from experienced developers about how to proceed and perhaps where to look for relevant tutorials. I am recently trying to develop a competitive ladder system for your typical videogame by using php and mysql.

This is what i got so far:
[url]http://www.xgs-gaming.com/tlt/files/ladder_system/[/url]

[b]I am aiming at a website which can[/b]

  • list up the rankings from a database like this page here:
  • [url]http://www.iccup.com/starcraft/ladder/1×1.html[/url]

  • when i press on a player i will see his profile, something like this:
  • (i want to keep things simple, all i want here is to display the characters information: rank country, and a link for a matchlist from his game that have been played)

    [url]http://www.iccup.com/starcraft/gamingprofile/splog.html[/url]

  • when someone presses the matchlist button a list of his previous matches comes up like this:
  • [url]http://www.iccup.com/starcraft/matchlist/928387/1×1.html[/url]

  • when players are logged in, they get options like:

  • *

    Report a win.
    (From this he will be able to select one of the players in the database he just won against, and a notification will be sent to that player.
    In order for the system to compute new points and ranks from functions i make, the other player will need to accept the loss first. )

  • [b]Later i’d like to add features like:[/b]

  • * Linking users to groups.
    (I’d like the users to get be able to select if they want to join a group or create an existing one)
  • [b]My questions:[/b]

  • How do i link tables togheter? I mean what would be the best way to store played matches? For example a table that consist of played matches linked to that spesific user. Would this require me to automaticly make an extra table each time a user gets created? So that when a player reports a win, the information would be stored there and a notification would be inserted in the other users table, the user that lost.

  • In this link:
    [url]http://www.iccup.com/starcraft/gamingprofile/splog.html[/url]
    When i press on one of the users, their profile shows up. And when i look at the url bar i can see that it ends with the users name.html. What does this mean? Are html files
    getting created for each user? I dont understand this concept.

  • My lack of experience just put a stop on my project after creating a membership system and displaying users from a database, i have created a couple of functions that
    calculate win_ratio and calculate a rank from points and some other stuff. But i dont know where to start from here, i’d like to be able to log in and report a win, and i just
    dont know how to do this, if i had some advice that would perhaps be of great help to me.

  • icant seem to figure out the 2 errors i got from the w3c validation:
    [url]http://validator.w3.org/check?uri=http%3A%2F%2Fwww.xgs-gaming.com%2Ftlt%2Ffiles%2Fladder_system%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.654[/url]

  • I hope this is not too much to ask.

    best of regards, alex

    to post a comment
    PHP

    13 Comments(s)

    Copy linkTweet thisAlerts:
    @GenixdeaeJan 13.2010 — Welcome dude! Hopefully we can get you started goin again ?, lotsa good minds here.

    In response to your questions:

    1) Tables links: I'd suggest having a table for users and one for battles(for starters). You can use [URL=http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html]foreign keys(FK)[/URL] to link the tables together. You users table would contain the users general information(location, name, ect). In your battles table you'd have a column for userID(store the ID that links to the user in the Users table). That will allow you to link your users table to your battle table. That should get you started. So you would saySELECT <span><code>result</code></span>, <span><code>battle_name</code></span> FROM <span><code>table</code></span> WHERE <span><code>userID</code></span> = '". $_SESSION["userID"] ."'; result would contain whether the user won or lost, and battle_name would contain the name of the battle. You could also make a battleID column that way you could click on a battle and use that ID to grab who the competitors were and who lost/won. You 'course would use however you store the users ID after they login(cookie/session/db table/ect) in place of $_SESSION["userID"]

    2) URL: Odds are they are using URL re-writing, though I can't be sure(I'm still researching URL re-writing). With that you can set it so that when the url reads domain.com/user.html the server will redirect to domain.com/index.php?u=user, but the browser displays the .html instead.

    3) Advice: Look for tutorials on google for creating a comments system. I know that's not what you're looking for, but all the things that creating a comments system involves will help you alot. A comment system uses your most common features of a dynamic site, update/delete/insert. Once you understand how those work, I think you'll have a better understanding of how you can use those features in other areas. More direct to your question though, you could make a page that the user fills in who they fought, what game and whatever else you want. When the user submits the page a 'message' will get sent to userX(who lost) notifying them.

    4) Errors: I believe you're getting those because you're putting a block item(<p>) inside a non-block item(<h2>), so if you swap them, should fix that.

    Hopefully that helps clarify a few things.
    Copy linkTweet thisAlerts:
    @inseiauthorJan 13.2010 — Thanks very helpful ? I was taking a hot shower and suddently got alot of ideas about how to do some of the stuff ?

    Im making a table for matchlist, and a table for pending matches to be confirmed, and just as u said about looser and winner and so on.

    Still havent figured out how to fix those links.. but i will check out the thing u mentioned.
    Copy linkTweet thisAlerts:
    @GenixdeaeJan 13.2010 — ...

    Still havent figured out how to fix those links..

    ..[/quote]
    You talking about how it displays the username in the url with a .html extension? Check this tutorial [url=http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/]here[/url] should help with that if that's what you're talking about.
    Copy linkTweet thisAlerts:
    @inseiauthorJan 13.2010 — thanks. i was also refering to how every user has a link in the list that directs them to their profile. I dont know to accomplish that.
    Copy linkTweet thisAlerts:
    @GenixdeaeJan 13.2010 — ah! This is something you'd learn how to do with a commenting system(or an announcement/news system would work). Pretty much, in your loop that lists all the users on the page you just add &lt;a href="index.php?u=&lt;?PHP echo $userID; ?&gt;"&gt;&lt;?PHP echo $userName; ?&gt;&lt;/a&gt; I imagine you're grabbing the username from the DB of users, do the same process for grabbing the ID of the user. You should have a Primary Key(PK) in your users table, and that's what you use as your userID. That make sense?
    Copy linkTweet thisAlerts:
    @inseiauthorJan 13.2010 — i understand, but im not familiar with index.php?u=... urls, i have made a shoutbox system before but never used anything like it. Would i learn this from the tutorial u linked me before?

    http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/
    Copy linkTweet thisAlerts:
    @inseiauthorJan 14.2010 — So this is what i got so far, i wanted to see if i could update the users with a function but it didnt seem to work..




    First function is to calculate a rank from points. (This works, tested).

    [CODE]function calculate_rank($points) {

    if ($points < 1000)
    return "f";

    if (($points >= 1000) && ($points < 1500))
    return "em";

    if (($points >= 1500) && ($points < 2000))
    return "e";

    if (($points >= 2000) && ($points < 2500))
    return "ep";

    if (($points >= 2500) && ($points < 3000))
    return "dm";

    if (($points >= 3000) && ($points < 3500))
    return "d";

    if (($points >= 3500) && ($points < 4000))
    return "dp";

    if (($points >= 4000) && ($points < 4500))
    return "cm";

    if (($points >= 4500) && ($points < 5000))
    return "c";

    if (($points >= 5000) && ($points < 5500))
    return "cp";

    if (($points >= 5500) && ($points < 6000))
    return "bm";

    if (($points >= 6000) && ($points < 6500))
    return "b";

    if (($points >= 6500) && ($points < 7000))
    return "bp";

    if (($points >= 7000) && ($points < 7500))
    return "am";

    if (($points >= 7500) && ($points < 8000))
    return "a";

    if (($points >= 8000) && ($points < 8500))
    return "ap";

    if ($points >= 8500)
    return "s";
    }[/CODE]




    This function converts the rank into number values so that later i can be

    able to use the amount of difference between ranks for calculating point updates. (This works, tested).

    [CODE]function rank_to_number($rank) {

    if ($rank == "f")
    return 0;
    if ($rank == "em")
    return 1;
    if ($rank == "e")
    return 2;
    if ($rank == "ep")
    return 3;
    if ($rank == "dm")
    return 4;
    if ($rank == "d")
    return 5;
    if ($rank == "dp")
    return 6;
    if ($rank == "cm")
    return 7;
    if ($rank == "c")
    return 8;
    if ($rank == "cp")
    return 9;
    if ($rank == "bm")
    return 10;
    if ($rank == "b")
    return 11;
    if ($rank == "bp")
    return 12;
    if ($rank == "am")
    return 13;
    if ($rank == "a")
    return 14;
    if ($rank == "ap")
    return 15;
    if ($rank == "s")
    return 16;
    }[/CODE]



    this function returns the amount of points that will be added to the winner points and subtracted from the looser points. (This works, tested).

    [CODE]function point_difference($strwrank,$strlrank) {

    $pconstant = 150;
    $pvariable = 30;

    $intwrank = rank_to_number($strwrank);
    $intlrank = rank_to_number($strlrank);

    $diff = $intwrank - $intlrank;
    $absdiff = abs($diff);

    if ((($pconstant-($pvariable*$absdiff)) < 0) && ($intwrank > $intlrank))
    return 0;

    else if ($intwrank > $intlrank)
    return ($pconstant-($pvariable*$absdiff));

    else if ($intwrank < $intlrank)
    return ($pconstant+($pvariable*$absdiff));

    else
    return $pconstant;
    }[/CODE]




    With this function i wanted to see if i could update the users, but that didnt work as i planned. I made 2 users for testing: Winner and Looser , u can see it here:

    http://www.xgs-gaming.com/tlt/files/ladder_system/index.php

    They are both at the bottom with 150points and -150 points, when it should be 3150points and 2850points. (starting point is 3000).


    [CODE]function action_update($winner,$looser) {

    $winnerrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$winner."'");
    $looserrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$looser."'");

    $pdiff = point_difference($winnerrow['Rank'],$looserrow['Rank']);

    $wpoints = $winnerrow['Points']+$pdiff;
    $lpoints = $looserrow['Points']-$pdiff;

    $wrank = calculate_rank($wpoints);
    $lrank = calculate_rank($lpoints);

    $wwin = $winnerrow['Win']+1;
    $lloss = $looserrow['Loss']+1;

    mysql_query("UPDATE ladder_users SET Points = '".$wpoints."', Rank = '".$wrank."', Win = '".$wwin."' WHERE Username = '".$winner."'");
    mysql_query("UPDATE ladder_users SET Points = '".$lpoints."', Rank = '".$lrank."', Loss = '".$lloss."' WHERE Username = '".$looser."'");
    }[/CODE]


    Database is allready connected.


    Also im not sure how the syntax should be, its so difference frmo tutorial to tutorial.. sometimes its

    SET Points = '".$lpoints."'

    and sometimes:

    SET Points = '$lpoints'

    i want to keep the syntax as simple as possible, which one is correct?
    Copy linkTweet thisAlerts:
    @GenixdeaeJan 14.2010 — From the looks of it, your code is re-assigning, not updating the 'points' value in the DB. I'd echo your $wpoints and all its associated values($winnerrow, $pdiff). See what gets displayed.

    as for the syntax. I'm not sure if it makes a diff other then preference. I don't *think* you need to do ". $var ." in a SQL query, but I could be wrong. I always code using ". $var .". In a query you use ` (thing above the tab key, left of the 1 key on keyboard) on tables and column names. You use ' (single quote) on values. The ". $var ." tells the code that you're going in be using PHP values inside quotes. This might help[code=php]$name = "yellow";
    echo "My Name is: ". $name .". What is yours?";[/code]
    ". says leave the quoted item , but don't exit it and ." says go back to the quoted item. I don't know what it's technically called.

    In response to your previous question. you can assign variables to get passed in the url, the easiest things to pass are ID's. Like on this forum if you look at the url it has t=xxxxxx the numbers that follow the t is the topic ID. You access the data by using [URL=http://www.php.net/manual/en/reserved.variables.get.php]$_GET[/URL] global variable.

    For some good tutorials I'd suggest going back to the [url=http://net.tutsplus.com/category/tutorials/php/]nettuts[/URL] site I linked to earlier and just look through the ones listed there. You might find some handy ones on there.
    Copy linkTweet thisAlerts:
    @inseiauthorJan 14.2010 — [CODE]function action_update($winner,$looser) {

    $winnerrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$winner."'");
    $looserrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$looser."'");

    $pdiff = point_difference("cm","d");
    echo $pdiff;
    /*

    $wpoints = $winnerrow['Points']+$pdiff;
    $lpoints = $looserrow['Points']-$pdiff;

    $wrank = calculate_rank($wpoints);
    $lrank = calculate_rank($lpoints);

    $wwin = $winnerrow['Win']+1;
    $lloss = $looserrow['Loss']+1;

    mysql_query("UPDATE ladder_users SET Points = '$wpoints', Rank = '".$wrank."', Win = '$wwin' WHERE Username = '".$winner."'");
    mysql_query("UPDATE ladder_users SET Points = '$lpoints', Rank = '".$lrank."', Loss = '$lloss' WHERE Username = '".$looser."'");

    */
    }

    action_update("Hannibal","Looser");[/CODE]

    This outputs 90 which is correct. But when i change the function code to:


    [CODE]function action_update($winner,$looser) {

    $winnerrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$winner."'");
    $looserrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$looser."'");

    $pdiff = point_difference($winnerrow['Rank'],$looserrow['Rank']);
    echo $pdiff;
    /*

    $wpoints = $winnerrow['Points']+$pdiff;
    $lpoints = $looserrow['Points']-$pdiff;

    $wrank = calculate_rank($wpoints);
    $lrank = calculate_rank($lpoints);

    $wwin = $winnerrow['Win']+1;
    $lloss = $looserrow['Loss']+1;

    mysql_query("UPDATE ladder_users SET Points = '$wpoints', Rank = '".$wrank."', Win = '$wwin' WHERE Username = '".$winner."'");
    mysql_query("UPDATE ladder_users SET Points = '$lpoints', Rank = '".$lrank."', Loss = '$lloss' WHERE Username = '".$looser."'");

    */
    }[/CODE]

    This outputs 150, which is the default return of the point_difference function. And this is not whats expected.

    but when i echo $winnerrow['Rank'];

    i get nothing.

    like this:

    [CODE]function action_update($winner,$looser) {

    $winnerrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$winner."'");
    $looserrow = mysql_query("SELECT * FROM ladder_users WHERE Username = '".$looser."'");

    $pdiff = point_difference($winnerrow['Rank'],$looserrow['Rank']);
    echo $winnerrow['Rank'];
    /*

    $wpoints = $winnerrow['Points']+$pdiff;
    $lpoints = $looserrow['Points']-$pdiff;

    $wrank = calculate_rank($wpoints);
    $lrank = calculate_rank($lpoints);

    $wwin = $winnerrow['Win']+1;
    $lloss = $looserrow['Loss']+1;

    mysql_query("UPDATE ladder_users SET Points = '$wpoints', Rank = '".$wrank."', Win = '$wwin' WHERE Username = '".$winner."'");
    mysql_query("UPDATE ladder_users SET Points = '$lpoints', Rank = '".$lrank."', Loss = '$lloss' WHERE Username = '".$looser."'");

    */
    }[/CODE]


    Then nothing gets output. dont know why.

    How can i check that i actually get the right information from the database? i cant echo it out so i cant find out what i get.
    Copy linkTweet thisAlerts:
    @inseiauthorJan 14.2010 — i forgot the mysql_fetch_array ?
    Copy linkTweet thisAlerts:
    @GenixdeaeJan 14.2010 — hah, it's always the simple things ?
    Copy linkTweet thisAlerts:
    @inseiauthorJan 14.2010 — thank you tho, you are very helpful and kind ?
    Copy linkTweet thisAlerts:
    @inseiauthorJan 14.2010 — bah another problem:

    i cant fill up a table.. arg so annoying >_<


    Here is the table:

    [CODE]CREATE TABLE ladder_matchlist (
    MatchID INT(25) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    Winner VARCHAR(65) NOT NULL ,
    Looser VARCHAR(65) NOT NULL ,
    Wchar VARCHAR(3) NOT NULL ,
    Lchar VARCHAR(3) NOT NULL ,
    Wnat VARCHAR(255) NOT NULL ,
    Lnat VARCHAR(255) NOT NULL ,
    Wrank VARCHAR(2) NOT NULL ,
    Lrank VARCHAR(2) NOT NULL ,
    Change INT(5) NOT NULL ,
    Date VARCHAR(100) NOT NULL,
    Stat VARCHAR(10) NOT NULL
    );[/CODE]


    This is the function and inputs:

    [CODE]action_update("bruce_willis","Draco","kaz","edd","2 - 1");

    function action_update($winner,$looser,$wchar,$lchar,$bo3) {

    $date = "DATO";

    $wrow = mysql_fetch_array(mysql_query("SELECT * FROM ladder_users WHERE Username = '".$winner."'"));
    $lrow = mysql_fetch_array(mysql_query("SELECT * FROM ladder_users WHERE Username = '".$looser."'"));

    $wrankpre = $wrow['Rank'];
    $lrankpre = $lrow['Rank'];

    $pdiff = point_difference($wrow['Rank'],$lrow['Rank']);

    $wpoints = $wrow['Points']+$pdiff;

    if (($lrow['Points'] <= 0) || ($lrow['Points']-$pdiff < 0) )
    $lpoints = 0;
    else
    $lpoints = $lrow['Points']-$pdiff;

    $wrankpost = calculate_rank($wpoints);
    $lrankpost = calculate_rank($lpoints);

    $wwin = $wrow['Win']+1;
    $lloss = $lrow['Loss']+1;

    mysql_query("UPDATE ladder_users SET Points = '".$wpoints."', Rank = '".$wrankpost."', Win = '".$wwin."' WHERE Username = '".$winner."'");
    mysql_query("UPDATE ladder_users SET Points = '".$lpoints."', Rank = '".$lrankpost."', Loss = '".$lloss."' WHERE Username = '".$looser."'");

    $testing = mysql_query("INSERT INTO ladder_matchlist (Winner,Looser,Wchar,Lchar,Wnat,Lnat,Wrank,Lrank,Change,Date,Stat)
    VALUES('".$winner."','".$looser."','".$wchar."','".$lchar."','".$wrow['Nationality']."','".$lrow['Nationality']."','".$wrankpre."','".$lrankpre."','".$pdiff."','".$date."','".$bo3."')");

    if ($testing)
    echo "worked";
    else
    echo "didnt work, debugging <br />";

    echo "Winner: ".$winner."<br />";
    echo "Looser: ".$looser."<br />";
    echo "Wchar: ".$wchar."<br />";
    echo "Lchar: ".$lchar."<br />";
    echo "Wnat: ".$wrow['Nationality']."<br />";
    echo "Lnat: ".$lrow['Nationality']."<br />";
    echo "Wrank: ".$wrankpre."<br />";
    echo "Lrank: ".$lrankpre."<br />";
    echo "Change: ".$pdiff."<br />";
    echo "Date: ".$date."<br />";
    echo "Stat: ".$bo3."<br />";

    }[/CODE]


    This is the output:

    didnt work, debugging

    Winner: bruce_willis

    Looser: Draco

    Wchar: kaz

    Lchar: edd

    Wnat: United_Kingdom

    Lnat: Brazil

    Wrank: cp

    Lrank: d

    Change: 30

    Date: DATO

    Stat: 2 - 1

    everything else works, i just cant seem to fill up that damn table with anything and i dont have any clue why >_< been sitting here and tried and tried for hours grrr
    ×

    Success!

    Help @insei spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...