Order Table by Last Name, First Name (Separate Fields) ?

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
sosapr
Posts: 12
Joined: 2013-02-18 18:10

Order Table by Last Name, First Name (Separate Fields) ?

Post by sosapr » 2015-09-25 12:25

My main table includes a Last Name field and a First Name field. The table is ordered by last name. Is there any way to make that table come up ordered by Last Name, and within that, by First Name?

Reason: When we go to add a person, we want to know if they are already in there, so we type in last name for the search. It would help if the results that pop up, showing all entries with that last name, were also in alpha order by first name.

Thanks!

lucicd
Posts: 13
Joined: 2015-09-16 08:48

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by lucicd » 2015-09-27 09:27

Hi,

Try to solve this in MySQL by creating an index on both last and first name. Something like this:

Code: Select all

CREATE INDEX full_name_idx ON people(last_name, first_name)
Of course, use table and field names that match your database.

Your sorting requirement will then come as a side effect of that index.

sosapr
Posts: 12
Joined: 2013-02-18 18:10

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by sosapr » 2015-10-05 18:11

Thank you.
Is there some way to make this code apply to the table of people that appears in my AppGini application?
Does this go into the php file in the hooks folder? If so, where?
Thanks.

lucicd
Posts: 13
Joined: 2015-09-16 08:48

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by lucicd » 2015-10-06 06:06

Alter hook file people.php by changing function people_init to look like this:

Code: Select all

function people_init(&$options, $memberInfo, &$args) {
	$options->DefaultSortField = "CONCAT(`last_name`, `first_name`)";
	return TRUE;
}

sosapr
Posts: 12
Joined: 2013-02-18 18:10

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by sosapr » 2015-10-06 12:07

THANK YOU!

I just went in and changed the php file and tried it out -- perfect! Very cool. I have a couple of other databases that I will alter the same way. Thank you for this help. Be well and safe.

- Mike H.

sosapr
Posts: 12
Joined: 2013-02-18 18:10

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by sosapr » 2015-10-06 17:05

One more thing -- it appears I need to re-edit the php file anytime I make a change and upload the AppGini files again. Is that right?

- Thanks

lucicd
Posts: 13
Joined: 2015-09-16 08:48

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by lucicd » 2015-10-06 23:36

Please explain what do you mean by uploading? IF you are talking about AppGini PHP code generator, hook files (PHP files in hooks folder) are not affected by it.

sosapr
Posts: 12
Joined: 2013-02-18 18:10

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by sosapr » 2015-10-07 11:57

This is helpful additional info for me. Whenever I make a change, I run AppGini PHP code generator, then FTP all files to the online server. This includes the hooks folder and all its PHP files. When I make a change, should I NOT UPLOAD some of the folders? What should I upload just to render the changes?

lucicd
Posts: 13
Joined: 2015-09-16 08:48

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by lucicd » 2015-10-08 07:55

If you make a change only in the hook file, there is no need to run AppGini PHP code generator. You can transfer only the file that you changed.

However, if you, for example, add new table and have to start code generator, then identifying changes is a bit complicated. One options could be to use advance features of FTP client such as FileZilla and let it identify and transfer only changed files.

There are many solutions in this area. The most basic one is to transfer all files and folders every time. It is slow, but it works. The most advanced include tools that monitor your local folder and then automatically transfer all changed files to the server. Use Google with keywords like "synchronize local and remote folder with ftp" and you will find the answer.

Another option is to use version control SW such as git. After you make change locally, commit them to your git repository (e.g. on Github) and then pull them to the server.

sosapr
Posts: 12
Joined: 2013-02-18 18:10

Re: Order Table by Last Name, First Name (Separate Fields) ?

Post by sosapr » 2015-10-08 15:03

Thanks for all your help tuning up my use of AppGini. I'll be uploading just what I need to, and I have local backup of the hook file just in case. I really appreciate all the help!

- Mike H.

Post Reply