[thelist] another mysql order problem
Dunstan Orchard
dunstan at 1976design.com
Sun Feb 2 19:00:00 CST 2003
Hi there,
another quick mysql query before I reply to your kind answers to my other
questions - I'm having trouble getting my results back in the order I want...
I have 2 tables:
***************
category
***************
categoryid
category
level
***************
***************
categoryparent
***************
categoryparentid
categoryid
parentid
***************
categoryid is the common factor between thos two tables.
My first query selects every category:
$query1 = ("SELECT category, categoryid FROM category ORDER BY category");
I then loop in this result array using the returned categoryid as my WHERE
variable:
$query2 = ("SELECT parentid FROM categoryparent WHERE (categoryid
= '$returned_categoryid')");
I then loop through _that_ result array and grab some more variables:
$query3 = ("SELECT level, category, categoryid FROM category WHERE
(category.categoryid = '$returned_parentid') ORDER BY category.level ASC");
All of that works fine - the problem is that query2 does not return the
results in any useful order and this messes things up for me when query3's
results are returned.
I need to order the results of query2 by category.level ASC, is there any way
to do this?
*********************************
Ideally I'd like to write:
$query2 = ("SELECT parentid FROM categoryparent WHERE (categoryid
= '$returned_categoryid') ORDER BY category.level");
*********************************
Can anyone suggest what I can do? I've tried reading all the manual stuff
about UNIONs and JOINs and so on, but I can't make head nor tail out of it
all :o/
Thanks in advance for any help,
Cheers - dunstan
---------------------------
Dorset, England
http://www.1976design.com/
http://www.orchard.it/
http://www.maccaws.org/
More information about the thelist
mailing list