SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lopping with descending order

    Ok, I have a loop set, but it reads as the table shows on SQL server, of course normal, but I want this to be sorted by the PlayerName, which is in the left column of my table.

    I know how to use the DESC command, but havent tryed, nor do I know much about it with a loop statement:

    PHP Code:
    while ( $row = mysql_fetch_array($result) ) {  
          $name = $row["PlayerName"];  
          $email = $row["PlayerEmail"];  
          $status = $row["PlayerStatus"];  
          $posistion = $row["PlayerPosistion"];  
          $age = $row["PlayerAge"];  
         
    ?>  
    <tr> 
    <td width="233" bordercolor="#808080" bgcolor="<?=$mycolor?>" style="height="17"><?=$name?></font></td> 
    <td width="506" bordercolor="#808080" bgcolor="<?=$mycolor?>" style="height="17"><?=$email?></font></td> 
    <td width="160" bordercolor="#808080" bgcolor="<?=$mycolor?>" style="height="17"><?=$age?></font></td>
    </tr>
    <?php 

         
    if ( $mycolor == gray ) {
            ( 
    $mycolor 333333 );
           } else { 
            ( 
    $mycolor gray );
        }



    ?>
    Where $name is, Id like the tables to be ordering DESC, by the first name. I know this is possible, Just have never read anything on this.

    Any help is appreciated, thanks in advance.

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should try adding order by PlayerName to the end of your sql query statement because that will do exactly what you want without you having to change another thing about your page.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not *that* expierenced in PHP/MySQL, but im pacing pretty well I guess, anyways, where exactly should I put the code, and if so, what *would* it be. I tried a few ways that I assumed would be somewhat correct, all failed. Although, I might have been on the correct path.

    Thanks for your response man, everything is appreciated. =)

  4. #4
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So is your problem solved or not?
    If not, what don't you understand or what isn't working?

    If you had included your sql statement I would have showed you how to put it right one there... ready for action
    You can still provide that part of the code if you want.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  5. #5
    (****** or Deleted)
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add the following to the end of your Select statement.

    Code:
    ORDER BY 'PlayerName'
    So it will look something like this:

    Code:
    $result = mysql_query("SELECT * FROM 'tblName' ORDER BY 'PlayerName' DESC");
    Make sense?
    Jordan Windebank

  6. #6
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Makes total sense, thanks alot samsm, and Wizardx8. =)

  7. #7
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more thing I ran into today, is there a query line to have it be sorted from last info added?

    =)

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    draft, what column can you use to indicate the sequence that the rows are entered? if the table has an auto_increment or timestamp, just put that column into the ORDER BY xxx DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use the ID, auto_increment, so yea, that worked perfecto, thanks. =)


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
  •