SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

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

    Newbie MySQL Question

    OK...im building this stats tracking for a video game where I input final results into the DB and it generates some output...i have most of it working...here is a Breif descrption of my problem

    PHP Code:
     <?php
    $db 
    mysql_connect($databaseserver$databaseuser$databasepass);
    mysql_select_db($databasename,$db);
    $sortby "margin_permap ASC";
    $sql="SELECT * FROM $playerstable ORDER BY $sortby";
    $result=mysql_query($sql,$db) or die (mysql_error());
    $num mysql_num_rows($result);
    $cur 1;

    echo 
    "<ol>";
    while (
    $num >= $cur) {
        
        
    $row mysql_fetch_array($result);
        
    $name $row["name"];
        
    $squad  $row["squad"];
        
    $scores $row["scores"];
        
    $kills $row["kills"];
        
    $deaths $row["deaths"];
        
    $maps_played $row["maps_played"];
        
    $margin_permap $row["margin_permap"];    
        
    $margin $scores-$deaths;
        
    $ratio $kills/$deaths;
        
    $deaths_permap $deaths/$maps_played;
        
    $scores_permap $scores/$maps_played;
        
    $kills_permap $kills/$maps_played;
        
    $margin_permap $margin/$maps_played;

        
    ?>
    I Can Not get the Output to show $MARGIN_PERMAP in the correct order best to worst..I can change the $sortby to kills and it will output correctly so that kinda tells me the Calculation Im making in this cant do the Fuction twice??

    by looking at the above info I supplied can you understand what Im trying to do...here is a Link of the output and notice how the LAST COLUMN doesnt sortby best to worst score..ADMIN should be listed in 1st place with 18.17


    LINK TO OUTPUT


    My Code may be CRUDE but I am TOTAL Newbie..actually just finished reading my 1st book...lol...but I love learning from everyone...any help would be appreciated...i think i know what problems are..just dont know how to fix it

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $num = mysql_num_rows($result);
    $cur = 1;
    echo "<ol>";
    while ($num >= $cur) {
    $row = mysql_fetch_array($result);
    This section would be more logical (and simpler) if you used:
    PHP Code:
    echo '<ol>';
    while(
    $row mysql_fetch_array($result)){
    ...

    also, when you're using string literals (that is, if there are no escaped characters and no variables within the string), use single quotes... it will increase performance...

    Regarding the actual question you need help with, I can't really tell what's going on there. Perhaps it would help if you showed us how the database is constructed, and maybe a few lines of sample data.

  3. #3
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm...not sure what you want to see

  4. #4
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also above code doesnt work for me


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
  •