Page 1 sur 1

prob liste option & enregistrement de l'id correspondant

Posté : 11 oct. 2006, 11:13
par jemoworld-in situe
bonjour...et au secours !!!!!


voilà mon soucis : j'affiche en php depuis un formulaire une liste déroulante contenant des options.

Selon la sélection faites dans cette liste je cherche à enregistrer l'ID correspondant à l'option choisie dans une table destinée à relier 2 tables et contenant donc 2 champs : id option et id produit.

pour afficher la liste d'option (dans mon formulaire d'enregistrement) voici le code que j'utilise :

Code : Tout sélectionner

<tr> <td class="fieldKey"><?php echo ENTRY_ACIDITE; ?></td> <td class="fieldValue"><?php echo tep_draw_pull_down_menu('acidite_id', tep_get_acidite(array(array('id' => '', 'text' => TEXT_ALL_ACIDITE)))); ?></td> </tr>
ce code appelle ma fonction :

Code : Tout sélectionner

function tep_get_acidite($acidite_array = '', $indent = '') { global $languages_id; if (!is_array($acidite_array)) $acidite_array = array(); $acidite_query = tep_db_query("select acidite_id, name from " . TABLE_ACIDITE ." where language_id = '" . (int)$languages_id ."' order by name"); while ($acidite = tep_db_fetch_array($acidite_query)) { $acidite_array[] = array('id' => $acidite['acidite_id'], 'text' => $indent . $acidite['name']); } return $acidite_array; }
jusque là ça marche...

mais comment enregistrer l'id de l'option correspondant au choix fait (de la liste deroulante) ainsi que l'id du produit pour lequel je selectionne cette option ?

ma table "acidite" contient toute mes options
ma table "products-to_acidite" relie les id products et id acidite

voici le code que je tente d'exploiter > sans succès

Code : Tout sélectionner

$products_to_acidite_query = tep_db_query("SELECT * FROM " . products_to_acidite . " WHERE products_id = " . (int)$products_id); while ($products_to_acidite = tep_db_fetch_array($products_to_acidite_query)) if ($HTTP_POST_VARS['acidite_id, product_id']) { // Check to see if there are any need to update table. foreach ($HTTP_POST_VARS['acidite_id']) { if (isset($acidite_id, $products_id)) { // an entry exists ? if ($val == '') tep_db_query("DELETE FROM " . products_to_acidite . " where products_id = " . (int)$products_id . " AND acidite_id = " . (int)$acidite_id . "); else tep_db_query("UPDATE " . products_to_acidite . " WHERE products_id = " . (int)$products_id . " AND acidite_id = " . (int)$acidite_id . "); } else { // an entry does not exist ! if ($val != '') tep_db_query("INSERT INTO " . products_to_acidite . " (products_id, acidite_id) VALUES ('" . (int)$products_id . "', '"(int)$acidite_id . "')"); } } }


:? :? merci pour votre aide !

ok voila LA solution

Posté : 11 oct. 2006, 14:07
par encore moi
il suffit dans le formulaire de mettre :

Code : Tout sélectionner

$products_to_acidite_query = tep_db_query("INSERT INTO " . products_to_acidite . " (products_id, acidite_id) VALUES ('" . (int)$products_id . "', '" . (int)$acidite_id . "')");