Hi,
I'm having problems with this function.
It works fine just to display the categories with an indent according to where they are to the parent categorie.
BUT when i would like to make it editable, so that people can change the categorie a certain picture should belong to.
Nothing is selected...
I hope somebody can help me out,
Thanks in advance
Gerry.
Here is the function:
function build_category_select_list($output='',$pid=0, $img_id){
$selected = array();
$sql = "SELECT * FROM download_cat_img WHERE image_id = '$image'";
$r = mysql_query($sql);
while($row = mysql_fetch_array($r)){
$selected[] = $row['categorie_id'];
}
static $i = 1;
$level = "level".$i;
${$level} = mysql_query("SELECT * FROM download_categorie WHERE parent_id = $pid AND id > 0 ORDER BY naam");
do{
$level = "level".$i;
while ($row = mysql_fetch_array(${$level})) {
if ($level == "level1") {
$indent = str_repeat("",$i);
} else {
$indent = str_repeat(" ",$i);
}
$naam = $row["naam"];
$cat_id = $row["id"];
$selected = in_array($cat_id, $selected) ? "selected" : "";
$output .= "<option value=$cat_id $selected>" . $indent.$naam ."</option>";
if ($row["child"] = 1) {
$i++;
$pid = $row["id"];
$level = "level".$i;
${$level} = mysql_query(" SELECT * FROM download_categorie WHERE parent_id = $pid AND id > 0 ORDER BY naam");
continue;
}
}
$i--;
if($i == 0){
break;
}
}while(1);
echo $output;
}