Re: Order by not working
- From: gordonb.eu0sl@xxxxxxxxxxx (Gordon Burditt)
- Date: Sun, 07 Sep 2008 17:56:41 -0500
Show me the query that is actually executed, after substitution of
any PHP variables.
Depending on which link I click on it's either
"SELECT * FROM browserinfo WHERE type='b' ORDER BY 'count' DESC";
or
"SELECT * FROM browserinfo WHERE type='b' ORDER BY 'postdate' DESC";
ORDER BY '$type', whatever is substituted for $type, is ordering
by a constant, and I'm curious as to how you could possibly think
the resulting order is wrong.
Simple, on one server it orders the results by either the count field or
the postdate field depending on which I want.
No, for the examples above, it's ordering by the *CONSTANT STRING*
'count' or 'postdate', which is not useful at all. You might as well
drop the ORDER BY or ORDER BY 'crap', it means the same.
You want:
ORDER BY count (hint: count is a field name)
or
ORDER BY `count` (hint: count is a field name)
*NOT*
ORDER BY 'count' (hint: count is a constant string)
On the other server it just
returns the info in the order that it's saved into the database no matter
what the 'order by' says.
According to your ORDER BY, all the rows have the *same* order, so
any order is acceptable.
ORDER BY type will order based on the type field, all of which have
the value 'b' due to the WHERE clause, so again I wonder how you
could possibly think the resulting order is wrong.
The displayed results stay the same no matter which I call. The query is
altering as I've added a line to print the query to the screen to make sure
the order by bit is altering.
Since you give a meaningless ORDER BY, any order is acceptable.
Please give a sample result which you think has "failed", and a
detailed reason WHY you think it "failed". I cannot think of any
way for there to be an incorrect order.
It's awkward to give the result as it's a big page and I don't particularly
want the info public. All I can say is on one server the data is displayed
in the correct order,
With the query you have given, *THERE IS NO WRONG ORDER*.
on the other the 'order by' bit is totally ignored.
For example, on one server the correctly displayed results could be
name count type date
Fred 999 b 12-08-2008
Bert 65 b 11-07-2008
John 12 b 16-07-2008
Where on the other server where ORDER BY 'count' could display the order in
Every row has the same value of the constant string 'count', so any
order of the rows is correct.
which they are stored in the database something like.
name count type date
Bert 65 b 11-07-2008
Fred 999 b 12-08-2008
John 12 b 16-07-2008
- Follow-Ups:
- Re: Order by not working
- From: Isaac Hunt
- Re: Order by not working
- References:
- Order by not working
- From: Isaac Hunt
- Re: Order by not working
- From: Gordon Burditt
- Re: Order by not working
- From: Isaac Hunt
- Order by not working
- Prev by Date: Re: Order by not working
- Next by Date: Re: Order by not working
- Previous by thread: Re: Order by not working
- Next by thread: Re: Order by not working
- Index(es):
Relevant Pages
|