sca_id; else $sca_id = -1; return $sca_id; } function options_categories($cat_id) { $result = mysql_query("select cat_id, cat_nom from categorie ". "order by cat_nom"); $first_cat_id = -1; while($row=mysql_fetch_object($result)) { if($first_cat_id == -1) $first_cat_id = $row->cat_id; echo "\n"; } return $cat_id == -1 ? $first_cat_id : $cat_id; } function options_sub_categories($cat_id, $sca_id) { $ret_val = $sca_id; $req = "select sca_id, sca_nom ". "from sous_categorie ". "where cat_id = ".$cat_id." ". "order by sca_nom"; $result = mysql_query($req); while($row=mysql_fetch_object($result)) { if($sca_id == -1 && $row->sca_nom == '') $ret_val = $row->sca_id; echo "\n"; } return $ret_val; // (should never be -1, but either $sca_id if $sca_id != -1 // or the id of the main sub-category (i.e. with a null name) } function js_update_options_sca() { echo "function update_options_sca(sca, ind_selection) {\n". " tab = new Array();\n"; $req = "select sca.cat_id, sca.sca_id, sca.sca_nom ". "from categorie cat, sous_categorie sca ". "where cat.cat_id = sca.cat_id ". "order by cat.cat_nom, sca.sca_nom"; $result = mysql_query($req); $cat_id_courant = -1; $no_ligne = -1; while($row=mysql_fetch_object($result)) { $non_vide = 1; if($row->cat_id != $cat_id_courant) { $cat_id_courant = $row->cat_id; if($no_ligne != -1) echo "\"\n"; $no_ligne++; echo "\ttab[$no_ligne] =\""; } echo "$row->sca_id;$row->sca_nom;"; } if(isset($non_vide)) echo "\";\n"; echo " tab2 = tab[ind_selection].split(';');\n". " sca.length = 0;\n". " for(i=0; i+1 < tab2.length; i = i+2)\n". " if(i==0)\n". " sca.options[i/2] = new Option(tab2[i+1], tab2[i], true, true);\n". " else\n". " sca.options[i/2] = new Option(tab2[i+1], tab2[i]);\n". " if(navigator.appName == 'Netscape') history.go(0);\n". "}\n"; } ?>