When we use jgGrid, like this:
get_items.php =>
$SQL = "SELECT * FROM items ORDER BY $sidx $sord LIMIT $start , $limit";
//$sidx is the index row.
//ie. $sidx = 'name';
$result = $mysql->query( $SQL );
header("Content-type: text/xml;charset=utf-8");
$s = "<?xml version='1.0' encoding='utf-8'?>";
...
//balah balah
...
while ( $row = $mysql->fetch_array( $result ) ) {
...
//Note the getName method.
$s .= "<cell>". getName($row['name']))."</cell>";
...
};
echo $s;
function getName ( name ) {
if ( name == 'Lane' ) return 'Brian Lane';
if ( name == 'Kerwin' ) return 'Diane Kerwin';
...
...
}
Now the question is :
if I sort the jqGrid by ASC, it will show like Diane Kerwin, Brian Lane as Kerwin is before Lane.
How to sort the fields like Brian Lane, Diane Kerwin by ASC?
Preferred solution
It looks like only the last names are stored in the database. To be able to sort by first name in your SQL query, you’ll need to update the
namefields in theitemstable to contain both first and last names. This would be much better — keeping a separate data set embedded in your code will probably cause problems at some point later on.If you must:
If this isn’t a possibility and you must keep the
ifstatements for each name, you could map over the result set to fetch the names and then sort. (The example below requires PHP >= 5.3.)