Page 1 of 1

ORDER by two column problem

Posted: Mon Jan 30, 2006 11:38 am
by ssand
Hi,

I am trying to ORDER by two columns.

Code: Select all

$inventory_list = "SELECT * FROM vehicles, inv_type
								WHERE inv_type.inv_type_name = '$_GET[get_inventory]'
								AND vehicles.inv_type_id = inv_type.inv_type_id
								AND vehicles.vehicle_active = 1
								ORDER by vehicles.$orderby, vehicles.$orderby2 $sortby
								LIMIT $offset, $rowsPerPage";
The results are correct except it seems to only be sorting by the first value (vehicles.$orderby).
If I echo the values of $orderby and $orderby the values are as expected.

If I take the:

Code: Select all

ORDER by vehicles.$orderby, vehicles.$orderby2 $sortby
and replace with:

Code: Select all

ORDER by year, price $sortby
the results are still only sorted by the year.

Thanks

Posted: Mon Jan 30, 2006 12:10 pm
by pickle
Output the query and see what it looks like. $sortby might not be what you expect.

Posted: Mon Jan 30, 2006 12:57 pm
by ssand
Well, the query looked ok on output. As coded before.

I went and changed the ORDER by to

Code: Select all

ORDER by vehicles.$orderby $sortby, vehicles.$orderby2 $sortby
And it seems to sort correctly.

Posted: Mon Jan 30, 2006 2:06 pm
by raghavan20
ssand wrote:The results are correct except it seems to only be sorting by the first value (vehicles.$orderby).
If I echo the values of $orderby and $orderby the values are as expected.
This will not be true. If you are first field in place, then the results will be sorted in asc or desc and asc by default. You might not have recognized it.

Posted: Mon Jan 30, 2006 2:20 pm
by ssand
raghavan20 wrote:
ssand wrote:The results are correct except it seems to only be sorting by the first value (vehicles.$orderby).
If I echo the values of $orderby and $orderby the values are as expected.
This will not be true. If you are first field in place, then the results will be sorted in asc or desc and asc by default. You might not have recognized it.
I think you may be absolutely correct. :oops: