SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Dallas, TX
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need ideas on way to do something....

    I am trying to get the last row of a table that is ordered by "rank" in Ascending order.... How can i do this?

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm... are they in ACS order in your database, or you sort tham that way when you submit the query?
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sort it by DESC and limit 1.
    ck :: bringing chris to the masses.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Dallas, TX
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok. So i would sort it so that the highest rank would be on top, how do i get that row? Im kinda new to PHP and MySQL

  5. #5
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you give us an example of say, 5 entries of your database? I'll be happy to write whatever code you need to get going, but I need your table structure first. Honestly I don't see how you can have entries in your database automaticly sorted by ranking... but then again...
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Dallas, TX
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, im not sure if that is possible. But what i had figured is you do:

    $result = mysql_query( "SELECT * FROM bz ORDER BY ASC" )

    Now im not sure if that would sort it right, but the table name that im working with is "bz". Fields: name, rank, id (auto increment), password.

    i need to save the highest "rank" to $lastrank so i can add to it...

    keep in mind that im new to MySQL so if it sounds like i dont exactly know what im doing it is prolly cuz i dont....

  7. #7
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hhmm. What exactly are you wanting to do? Try to describe it like you would to a non coder... then maybe I'll be able to decifer it. Then again maybe someone else will be able to better decifer what you're looking for.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Location
    Dallas, TX
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im trying to take the highest "rank" and add 1 to it. And when i did this in ASP, the way i did it was i sorted it in ASC order by rank. and then did objRS.MoveLast

    What this is for is a gaming ladder. And when someone joins they become the highest ranked team/player. So i have to take the highest previous rank and add 1 to it

  9. #9
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP really makes your job quite easy just use AUO_INCREMENT!

    OR... if I'm misunderstanding, which I think I am...

    PHP Code:
    $sql "SELECT rank FROM $table ORDER BY rank ASC LIMIT 0, 1";
    $result mysql_query($sql);
    while(
    $row mysql_fetch_array($result)){
        
    extract();
        
    $rank++;
        
    $sql "INSERT INTO $table SET rank='$rank'";
        if(!
    mysql_query($sql)){
           echo(
    "Error");
        }

    Last edited by exbabylon; Aug 21, 2001 at 20:57.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


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
  •