SkyRanger Posted April 28, 2007 Share Posted April 28, 2007 I am trying to figure out how to order a list of names by last name (not really sure if this is possible): This is what I have so far but it's not working right: $resultab = mysql_query( "SELECT abname from address where fname='$logged' order by abname ASC") or die( "Unable to select database"); So If I had: John Smith Jack Brown Chris Andrews Jane Doe I need the list to output Chris Andrews Jack Brown Jane Doe John Smith Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/ Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 do you have a field for last name ? Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240156 Share on other sites More sharing options...
SkyRanger Posted April 28, 2007 Author Share Posted April 28, 2007 No, first and last are in the same field Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240177 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 OK thats a pain, personally i don't think so.. if you can i don't think it's easy (someone surprise me, and prove me wrong) Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240181 Share on other sites More sharing options...
SkyRanger Posted April 28, 2007 Author Share Posted April 28, 2007 I wasn't sure either, going to be doing some research on this to find out if possible, maybe even email the mysql developers to see what they say. If anybody else has an answer though please post, this may be helpful for allot of people Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240228 Share on other sites More sharing options...
SkyRanger Posted April 28, 2007 Author Share Posted April 28, 2007 ~bump~ Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240301 Share on other sites More sharing options...
SkyRanger Posted April 28, 2007 Author Share Posted April 28, 2007 ~bump~ Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240499 Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 You can select abname. and then explode by ' ' <space>. then order (sort) the array in Ascending or descending order. Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240505 Share on other sites More sharing options...
SkyRanger Posted April 28, 2007 Author Share Posted April 28, 2007 huh....lol, can anybody elaborate for us noob's please Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240534 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 basically neel_basu is saying do it outside the mysql request, Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240557 Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 Use array_multisort() to sort the exploded array. array_multisort() explode ----------------------------------------------- First get the contents from Database Using Select Statements and Store it in a string array named $full_name. And then Do this following. <?php $last_name = array(); foreach($full_name as $val) { $tmp = explode(" ", $val); $last_name[] = $tmp[1]; } unset($full_name); array_multisort($last_name, SORT_ASC, SORT_STRING, $filtered_array); print_r($filtered_array); ?> Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240566 Share on other sites More sharing options...
SkyRanger Posted April 28, 2007 Author Share Posted April 28, 2007 Awsome, thank you very much, I bet this will help allot of people out. Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240576 Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 Dont forget to unset the $last_name for more speed and performance at the end. Quote Link to comment https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.