somedude Posted January 24, 2007 Share Posted January 24, 2007 IF i have a db table like this. Where the categories are in the left column and products in the right column.[table] [tr] [td]1[/td] [td]1[/td] [/tr] [tr] [td]1[/td] [td]2[/td] [/tr] [tr] [td]2[/td] [td]3[/td] [/tr] [tr] [td]2[/td] [td]4[/td] [/tr] [tr] [td]2[/td] [td]5[/td] [/tr] [tr] [td]3[/td] [td]6[/td] [/tr][/table]How can i display these like[b]1[/b] 1 2[b]2[/b] 3 4 5[b]3[/b] 6Thank you for any help. Link to comment https://forums.phpfreaks.com/topic/35484-display-products-under-categories/ Share on other sites More sharing options...
suzzane2020 Posted January 24, 2007 Share Posted January 24, 2007 I guess wat u mean here is tht1 is the categoryand2,3 are its subcategoriesin tht case u need to put them in dif tables with a connecting id1st tableid(autoincrement) category1 category 12 category 2table 2connectingid(nt autoincrement.u need to insert it) subcategory1 sub1(subcategory of category 1)1 sub2(subcategory of category 1)2 sub3(subcategory of category 2)2 sub4(subcategory of category 2) Link to comment https://forums.phpfreaks.com/topic/35484-display-products-under-categories/#findComment-167898 Share on other sites More sharing options...
somedude Posted January 24, 2007 Author Share Posted January 24, 2007 Yeah that's right. But how to display them like i want?Can it be done with some nifty select query and while loop? Link to comment https://forums.phpfreaks.com/topic/35484-display-products-under-categories/#findComment-167900 Share on other sites More sharing options...
suzzane2020 Posted January 24, 2007 Share Posted January 24, 2007 yup u cud use a quer like this$query=mysql_query("select * from catgory");while($row=mysql_fetch_array($res)){ //second query goes here $query2=mysql_query("select subcategory from subcategory(tablename) where connectinid='$row["id"]'"); while($row2=mysql_fetch_array($query2)){ echo $category; echo $subcategory;}}//u cud use html to display it in a better format Link to comment https://forums.phpfreaks.com/topic/35484-display-products-under-categories/#findComment-167902 Share on other sites More sharing options...
suzzane2020 Posted January 24, 2007 Share Posted January 24, 2007 sorry ..in the first while loop its $query instead of $res. Link to comment https://forums.phpfreaks.com/topic/35484-display-products-under-categories/#findComment-167903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.