Array and mysql join

HI,
I have two tables

Catagory

id name
1 abc
2 def
3 bcd
4 fff

Subcatagory
cid sid name
1 1 subname1
1 2 subname2
2 3 subname3
1 4 subname4

Now I have a group array
i.e
Group1-> 1,3,4
Group2->1,4

Now as group is an array not a table , I cannot join to find out subcatagory id&name. Of course I can run select with where clause to find subcatagory.
But , I was wondering is there a better way to show catname&subcatname
by group ?

Hope it is clear.

No, I’m afraid it’s not entirely clear. What do you mean by “group”? How do “groups” relate to the categories and subcategories?

Hi , thanks for reply.

$group1=array(‘1’,‘3’,‘4’);
$group2=array(‘1’,‘4’);

so group1 will show

cid subcatid name
1 1 subname1
1 2 subname2
3 5 subname5
4 4 subname4

In that case you could try something like


$query='SELECT something FROM daTable WHERE id IN ('.implode(',', $group1).')';
// SELECT something FROM daTable WHERE id IN (1,3,4)

Hi thanks a lot for reply.