Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6141453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:15:11+00:00 2026-05-23T18:15:11+00:00

When we use jgGrid, like this: get_items.php => $SQL = SELECT * FROM items

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:15:11+00:00Added an answer on May 23, 2026 at 6:15 pm

    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 name fields in the items table 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 if statements for each name, you could map over the result set to fetch the names and then sort. (The example below requires PHP >= 5.3.)

    $SQL = "SELECT * FROM items ORDER BY $sidx $sord LIMIT $start , $limit";
    $result = $mysql->query($SQL);
    
    $rows = array();
    while ( $row = $mysql->fetch_array($result) ) {
        switch ( $row['name'] ) {
            case 'Lane': $row['name'] = 'Brian Lane';
            case 'Kerwin': $row['name'] = 'Diane Kerwin';
        }
    
        array_push($rows, $row);
    }
    
    usort($rows, function($a, $b) { return strcmp($a['name'], $b['name']); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: Use stype:'select' for 'Client' column in search popup. The dataUrl for this column
use this website a lot but first time posting. My program creates a number
On the demo website for jqGrid, the columnChooser module is displayed like this: It
I want to create a property grid like this: Ext JS Property Grid demo
I am trying to use the jQuery-based Wijmo WijMenu control with jqGrid in order
i am leveraging this project to use jqgrid to filter and sort collections .
My Colmodel in javascript looks like this jQuery(#testGrid).jqGrid( //Some code colModel: [ { name:
Thanks to Oleg, my jqGrid now looks like this, and works fine. (my problem
I use jqGrid and my grid definition is like that: ... colNames:['Type','Date','Message','User Name','Host'], colModel:[{name:'type',index:'type',
I am using a jqgrid where I'd like to use inline editing and mask

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.