Something like this may work note its untested though
SELECT * FROM Members ORDER BY SUBSTRING_INDEX(name, ' ', -2)
It should select the first 2 words that appear to the right of the first space. That should allow for middle name and surname.
OK this'll work too its messy/compute heavy but works. Its horrible with loop within loop but short of fixing your db to a proper structure this is as good as you'll get (unless you wanna go into the black magic of regex.
$surnamesarray = array();
$sql = "SELECT * FROM Members";
$self = mysql_query($sql);
while ($row = mysql_fetch_array($self)) {
$temparray = explode(" ",$row['name']);
$substring = "";
for ($i=0;$i<count($temparray);$i++) {
$substring .= " ".$temparray[$i];
}
$surnamesarray[] = trim($substring)
}
// now we just array sort so
sort($surnamesarray);
var_dump($surnamesarray);//you would now for each this array again to display i'm just dumping out here