Is there a MYSQL or PHP method to display an item first before all others then display the rest of my items alphabetically?
SELECT client_name FROM clients ORDER BY client_name ASC
Gives me the following list:
Except I am looking for a way to display them in order like this.
or like this depending on which one I need first ...
You can use something like this:
SELECT client_name FROM clients ORDER BY client_name != 'Harold', client_name
The client_name != 'Harold' part is false for 'Harold' and true for every other row, so 'Harold' will be first. After that, you sort the rows where it's true by client_name.
If you wanted to do this in MySQL, you could use an union:
SELECT client_name FROM clients WHERE client_name = 'Harold'
UNION SELECT client_name FROM clients WHERE client_name != 'Harold' ORDER BY client_name ASC
I'd rather use Lukáš Lalinský's suggestion though, that was great.
Or, just filter it out in PHP:
$result = mysql_query("SELECT client_name FROM clients ORDER BY client_name ASC");
$head = array();
$tail = array();
while($row = mysql_fetch_assoc($result)) {
if($row['client_name'] == 'Harold') {
$head[] = $row;
} else {
$tail[] = $row;
}
}
$result = array_merge($head, $tail);
SELECT client_name FROM clients ORDER BY client_name ASC LIMIT 1
you will get $clientname
then:
SELECT client_name FROM clients ORDER BY client_name ASC LIMIT 1,99999
OR:
SELECT client_name FROM clients WHERE client_name<>$clientname ORDER BY client_name ASC