Re: Order by not working



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
.



Relevant Pages

  • Re: Order by not working
    ... Depending on which link I click on it's either ... On the other server it just ... John 12 b 16-07-2008 ... Where on the other server where ORDER BY 'count' could display the order in ...
    (comp.lang.php)
  • Re: Q. Is 19 fields too much for a query ?
    ... To add to Fred's comments, be aware that, depending on various factors ... your query may or may not be "updateable". ... So, if the purpose is to display the query's data on a form, this will ... > There shouldn't be any problem making the query or displaying the ...
    (microsoft.public.access.formscoding)
  • Re: WQL Query / Properties order and Limit amount of results
    ... if I run a query against one of my server Application logs ... To switch on your light, I'd like to display in a list, datas about ...
    (microsoft.public.win32.programmer.wmi)
  • IIf Null, then hide
    ... I have a form based on a query that will display one ... Depending on the ... some or all of the textboxes will be ...
    (microsoft.public.access.formscoding)
  • strange effects with connected servers
    ... The database "vertrieb" is merge-replicated with Server "S2". ... Now we get the following results depending on which server we run the query: ...
    (microsoft.public.sqlserver.server)