sort mysql column using php
Hi
I have put a sort feature using php and works perfect on all the columns apart from one column, It has values of Y and N and would be good if I can get it so all the Y's are together and the N's are together and the Y or N appear at the top first, hope that makes sense
below is the code I have
PHP Code:
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'id';
$sort_order = 'asc';
if(isset($_GET['sort_by']))
{
if($_GET['sort_by'] == 'asc')
{
$sort_order = 'desc';
} else
{
$sort_order = 'asc';
}
}
switch($sort)
{
case 'id':
$order_by = 'id';
break;
case 'software_name':
$order_by = 'software_name';
break;
case 'used':
$order_by = 'used';
break;
}
// get the records from the database
if ($result = $mysqli->query("SELECT id, software_name, software_key, used FROM software_keys ORDER BY $sort $sort_order LIMIT $start_from, $per_page"))
echo "<tr>
<th><a href='view-software-keys.php?sort=id&sort_by='.$sort_order.''>Software ID</a></th>
<th><a href='view-software-keys.php?sort=software_name&sort_by'.$sort_order.''>Software Name</a></th>
<th>Software Key</th>
<th><a href='view-software-keys.php?sort=used&sort_by='.$sort_order.''>Used</a></th>
<th>Actions</th>
</tr>";
Sorry