Okay so you were missing a closing bracket for your function and also
PHP Code:
<option value="<?=$tcats[$key][$jey][id]?>"><?=$tcats[$key][$jey][$Name]?></option>
<option value="<?=$tcats[$key][$jey][id]?>"> <?=$tcats[$key][$jey][$Name]?></option>
See how you have $Name in the last brackets it hsould be Name
PHP Code:
<option value="<?=$tcats[$key][$jey][id]?>"><?=$tcats[$key][$jey][Name]?></option>
<option value="<?=$tcats[$key][$jey][id]?>"> <?=$tcats[$key][$jey][Name]?></option>
This works on my machine
PHP Code:
<?
function ShowCatList() {
Connect();
$result = mysql_query("select id, Name, Parent_ID from categories order by Parent_ID");
while($row = mysql_fetch_array($result)) {
extract($row); //loads the array $row into variables for each column(id becomes $id)
//same as $id=$row["ID"]; for each column
if($Parent_ID == 0) { //If the parent id is 0 then this is a main cat
$tcats[$id][] = array("id" => $id,
"Name" => $Name,
"Parent_ID" => $Parent_ID);
}
else { //Or else this is a subcat
$tcats[$Parent_ID][] = array("id" => $id,
"Name" => $Name,
"Parent_ID" => $Parent_ID);
}
}
?>
<select name="categories">
<option value="">SELECT CATEGORY</option>
<?
foreach($tcats as $key => $val) {
if(is_array($tcats[$key])) {
foreach($tcats[$key] as $jey => $jal) {
if($tcats[$key][$jey][Parent_ID] == 0) {
?>
<option value="<?=$tcats[$key][$jey][id]?>"><?=$tcats[$key][$jey][Name]?></option>
<?
}
else {
?>
<option value="<?=$tcats[$key][$jey][id]?>"> <?=$tcats[$key][$jey][Name]?></option>
<?
}
}
}
}
?>
</select>
<?
}
ShowCatList();
?>
Bookmarks