SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Sort by element of array

    Hi All,

    I have

    $rowsort[] = $row;

    I'm trying to sort that by the city which is element 13 of $rowsort.

    kind of like
    sort($rowsort[13])

    which doesnt work.

    I'm sure that I have done this before but I'm just not getting this.

    Any help will be appreciated.

    Lorenw

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not sort on the city column in your sql query ?
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I am just learning the sql end of php and didn't even think of that.

    so I just tried this but its not working

    Code:
    	$result = mysql_query("
    SELECT * 
      FROM users_data ORDER BY user_city ASC
    inner
      join lstct 
        on lstct.uid = users_data.user_id
    	and lstct.st = '$mystate'
    	and lstct.ct = '$county'
        and lstct.ret = 0
       ");
    once this works I can make some other routines smaller.

    thanks
    lw

  4. #4
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Close, you just put ORDER BY in the wrong place. ORDER BY is always the last clause in a SELECT statement:
    Code:
    SELECT * 
      FROM users_data
    inner
      join lstct 
        on lstct.uid = users_data.user_id
    	and lstct.st = '$mystate'
    	and lstct.ct = '$county'
        and lstct.ret = 0
    ORDER BY user_city ASC
    PHP questions? RTFM
    MySQL questions? RTFM

  5. #5
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Awesome, Thanks I'm off to my next stone wall.

    Learning is a good thing no matter how much your brain hurts.

  6. #6
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, in the interest of learning, I was wrong - ORDER BY is not always the last clause. The manual is a very good resource: http://dev.mysql.com/doc/refman/5.0/en/select.html
    PHP questions? RTFM
    MySQL questions? RTFM

  7. #7
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,098
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I saw that and then saw the ASC on another page and tried that when ORDER BY did not work, I still would not have a clue if not for your help

    I have a lot to learn but I do know about my_real_escape_string and the security stuff and am very happy that what I have going screams along, it has 2500 members and my ajax queries are so fast I made the script sleep for two seconds so the user could see that it was looking up instructors. I really expected it to be slow and this is my first database to be used by the public on a large (for me) scale

    thanks
    cheers and beers
    LW


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
  •