Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2004
    Location
    Arlington, TX
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Sorting arrays by value

    Can anyone help?

    Here's my problem: I am working on a OOP module for sorting a mysql result set by distance from a specified zip code. Say I query the database like this: "SELECT id, name, city, state, zip, phone FROM contacts WHERE city= 'Dallas'". I then pass this to the class. For each result returned I used an "array_push" and added a ziplocateddistance to each result array.

    Here's what I need help with: I need to sort the array by the ziplocateddistance. That's all! I just need some help. There's no php function that will do this to my knowledge. If anyone can help I would greatly appreciate it! I need to finish this by Saturday.

    Thanks,
    Josh
    Last edited by JBChris; 06-15-2005 at 11:32 PM.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    isn't it just sort() or asort() ? http://uk.php.net/manual/en/function.sort.php
    http://uk.php.net/manual/en/function.asort.php

    i also do't realy see why you need an array_push... you can just dump the resultset in a 2D-array end then add a new elemet for the distance.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Sep 2004
    Location
    Arlington, TX
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, I forgot to mention, It's a 3D array.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no problem.

    just read the usercomments in the two pages i linked to. there is plenty of examplecode inthere to sort all sorts of arrayw in different ways.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •