Jump to content

order by


SkyRanger

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/49024-order-by/
Share on other sites

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/49024-order-by/#findComment-240566
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.