Primary Key Field Affecting Sorting of Data

Talk about Sorting & Paging problems, issues etc.

Moderator: alexandrleonenko

stevenp
Newbie
Newbie
Posts: 7
Joined: Mar 19th, '10, 22:36

Primary Key Field Affecting Sorting of Data

Postby stevenp » Mar 19th, '10, 23:07

Hello,

First off, thanks for this wonderful piece of software. I'm having a problem with my table whereby I am trying to have the data displayed by District, Address, House Number. Each of those fields is set as an index in the table and the primary/key field is ID [int(6), auto-increment].

My results are being sorted and displayed by ID, then District, etc. as shown in TABLE A. How can I get my resulting table to be like TABLE B as opposed to TABLE A. The ID Field is not needed in my results.

TABLE A
ID District Address House #
1 "Welchman Hall" "Welch Garden" 3
2 "Welchman Hall" "Welch Garden" 4
3 "Welchman Hall" "Welch Garden" 2
4 "Welchman Hall" "Welch Garden" 8

TABLE B
ID District Address House #
3 "Welchman Hall" "Welch Garden" 2
1 "Welchman Hall" "Welch Garden" 3
2 "Welchman Hall" "Welch Garden" 4
4 "Welchman Hall" "Welch Garden" 8


I hope I have been clear.

TIA,
Steven Parris

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: Primary Key Field Affecting Sorting of Data

Postby administrator » Mar 21st, '10, 09:28

What's the role of sorting in table B?

stevenp
Newbie
Newbie
Posts: 7
Joined: Mar 19th, '10, 22:36

Re: Primary Key Field Affecting Sorting of Data

Postby stevenp » Mar 21st, '10, 14:05

Hello,

Thanks for your response. Perhaps I used the term Table incorrectly. My post should probably have read Figure A, Figure B. I'm sorry for the misunderstanding. However, my question still stands... how do I get the data sorted the way I want, without the ID (Primary Field) interfering with the process?

Steven

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: Primary Key Field Affecting Sorting of Data

Postby administrator » Mar 22nd, '10, 07:48

You must have some field for sorting otherwise you will get something unexpected.

stevenp
Newbie
Newbie
Posts: 7
Joined: Mar 19th, '10, 22:36

Re: Primary Key Field Affecting Sorting of Data

Postby stevenp » Mar 22nd, '10, 13:16

I'm trying to have my results sorted as follows:

by District, then by Address within that District, then by House Number within that Address.

The relevant sections in the code_template.php are set as follows:

$sql = "SELECT * FROM voters";
.
.
.
$default_order_field = "district, address1, house_block_number";

each of those fields is indexed.

stevenp
Newbie
Newbie
Posts: 7
Joined: Mar 19th, '10, 22:36

Re: Primary Key Field Affecting Sorting of Data

Postby stevenp » Mar 26th, '10, 11:48

Can anyone help with this problem? I am extremely desperate... PLEASE!!

administrator
Site Admin
Site Admin
Posts: 5997
Joined: Jan 7th, '09, 23:18
Contact:

Re: Primary Key Field Affecting Sorting of Data

Postby administrator » Mar 28th, '10, 08:28

1. You have to define fields in SELECT SQL and Promary Key on the first place

2.
$default_order_field = "field_name_1, field_name_2, field_name_3 ";
$default_order_type = "ASC, ASC, ASC";

stevenp
Newbie
Newbie
Posts: 7
Joined: Mar 19th, '10, 22:36

Re: Primary Key Field Affecting Sorting of Data

Postby stevenp » Mar 29th, '10, 23:31

Thanks!! I think that may have done the trick... I'll bug you again if I run into trouble :D


Return to “Settings: Sorting & Paging”