Page 1 of 1

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

Posted: 2015-09-25 12:25
by sosapr
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!

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

Posted: 2015-09-27 09:27
by lucicd
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.

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

Posted: 2015-10-05 18:11
by sosapr
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.

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

Posted: 2015-10-06 06:06
by lucicd
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;
}

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

Posted: 2015-10-06 12:07
by sosapr
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.

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

Posted: 2015-10-06 17:05
by sosapr
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

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

Posted: 2015-10-06 23:36
by lucicd
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.

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

Posted: 2015-10-07 11:57
by sosapr
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?

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

Posted: 2015-10-08 07:55
by lucicd
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.

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

Posted: 2015-10-08 15:03
by sosapr
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.