Hi...
I read your post... This thing will be a problem to do because, you do not have anythng common in the Table1 and Table2. Im not sure how much you have idea about the Database Normalization thing, but this is actually not a correct way to implement the database thing.
I know you have the parent category id in table 2, but then the parent id might not be the category of the item... I hope you get me..
So for this, first correct your tables structure...
I'll suggest you one structure..
Table1 -Perfect
- Item
- CategoryID
Table2 - Needs change
- CategoryID
- Category Name
- Parent CategoryID
If you have the above structure, then you may not even need the parent category name table (Table 3), because you can get parent category name from the table itself..
Anyways, a big lecture i suppose... I'll come to code now...
So if you implement as per the database i told you... then the following code will work...
<?php
$sql1 = "Select table2.categoryID,table2.categoryName from table1,table2 where table1.categoryID=table2.categoryID and table1.item_info=2";
//2 is some value of the item coresponding to which the categories are to be chosen..
$result1 = mysql_query($sql1);
?>
<select name="options_tab">
<?php
//First show all of the from table 1
while($row1 = mysql_fetch_array($result1))
{
?>
<option value="<?php echo $row1[0]; ?>"><?php echo $row1[1];?></option>
<?php
}
?>
</select>
If you are looking for some different result, then you can change the sql query but the basic idea remains the same...