Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.