Jump to content

Display products under categories


somedude

Recommended Posts

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]
  6

Thank you for any help.
Link to comment
https://forums.phpfreaks.com/topic/35484-display-products-under-categories/
Share on other sites

I guess wat u mean here is tht

1 is the category
and
2,3 are its subcategories

in tht case u need to put them in dif tables with a connecting id

1st table

id(autoincrement)    category
1                          category 1
2                          category 2


table 2

connectingid(nt autoincrement.u need to insert it)                    subcategory

1                                                                                        sub1(subcategory of category 1)
1                                                                                        sub2(subcategory of category 1)
2                                                                                        sub3(subcategory of category 2)
2                                                                                        sub4(subcategory of category 2)
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.