PDA

View Full Version : how to display this data


xiaodao
02-02-2006, 03:53 AM
database

//maincat

catid
catname
displayorder

//subcat

subid
subname

//photo
photoid
photoname

then i have this script to extract three table's data together

$sql=$db->query("SELECT DISTINCT(b.catid),a.photoid,a.photoname,b.subname,c.catname FROM ".$db_prefix."photo AS a INNER JOIN (".$db_prefix."subcat AS b INNER JOIN ".$db_prefix."cat AS c ON b.catid=c.catid) ON a.subid = b.subid GROUP BY b.catid");


the above query is working, but now the displaying order is according to catid, but i want to according to displayorder, how to do now

raf
02-02-2006, 10:08 AM
just add an ORDER BY clause to the select-statement.

xiaodao
02-02-2006, 04:06 PM
Hi, no successful when i add ORDER BY c.displayorder, got sql error

fci
02-02-2006, 04:13 PM
where did you put the order by? it would go after the group by. and post the error you're getting if you still have problems

xiaodao
02-02-2006, 06:49 PM
hi, i added according to your instruction, no error, but the data does not sort accoring to the display order, the data still sort according to the catid...how to solve? thanks

fci
02-02-2006, 07:01 PM
well, if you have the order by in there and it doesn't show what you would expect then the problem is with your data, not with the query. why not loop through the results and echo the value of c.displayorder to see what is up.