Forum Moderators: coopster
and the second table
scm_store_cat_desc
cat_id cat_title
1 Australia
2 New Zealand
3 North Island
4 South Island
5 New South Wales
6 Victoria
7 Bay of Plenty
8 Waikato
9 Otago
10 Nelson
21 St Clair
12 Queenstown
13 Cromwell
14 Dunedin
16 Westland
17 Southland
18 Canterbury
I am trying to make a query that will produce a drop down box to select the catagory you want. Showing the parent catagories and the children under them indented.
example:
Australia
-New South Wales
-Sydney
-Victoria
-South Australia
New Zealand
-North Island
-Bay of PLenty
-Waikato
-South Island
-Nelson
-Otago
-Dunedin
-Cromwell
and so on, so far this is the only code i have been able to get my head around but cant find the way to get the whole thing together
<select >
<?php$query = "SELECT cat_id FROM scm_store_item_to_cat WHERE item_id = $item_id;";
$result = mysql_query($query) or die ("Query failed: ".mysql_error());
$row = mysql_fetch_array($result);
$current_cat_id = $row['cat_id'];
$query = "SELECT * FROM scm_store_cat ORDER BY cat_parent_id;";
$result = mysql_query($query) or die ("Query failed: ".mysql_error());
$num_results_data = mysql_num_rows($result);
for ($i=0; $i < $num_results_data; $i++)
{
$row = mysql_fetch_array($result);
$cat_parent_id = $row['cat_parent_id'];
$cat_id = $row['cat_id'];
$query2 = "SELECT cat_title FROM scm_store_cat_desc WHERE cat_id=$cat_id;";
$result2 = mysql_query($query2) or die ("Query failed: ".mysql_error());
$row2 = mysql_fetch_array($result2);
$cat_title = $row2['cat_title'];
echo 'Parent ID = '.$cat_parent_id.' - Cat ID = '.$cat_id.' - '.$cat_title.' <br />';
}
?>
</select>