patheticsam Posted May 14, 2010 Share Posted May 14, 2010 Hi! I have a small form on my website which will be already filled out with some data contained into a MySQL DB. Everything works fine except for the select boxes who's not displaying the value from the DB. Here's my code : <?php //connect to my SQL here if( ($_GET['cmd']=="view") && (is_numeric($_GET['id'])) ) { $id=$_GET['id']; $data = mysql_query("SELECT * FROM opportunite WHERE id='$id'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo " <tr> <td style=\"text-align: center;\" colspan=\"2\"><h1>Fiche Client</h1></td> </tr> <tr> <td>Nom de l'entreprise : </td> <td style=\"text-align: right;\"><input type=\"text\" name=\"entreprise\" value=\"".$info['entreprise']."\" style=\"width: 200px;\"></td> </tr> <tr> <td>Date : </td> <td style=\"text-align: right;\"><input type=\"text\" name=\"date\" value=\"".$info['date']."\" style=\"width: 200px;\"></td> </tr> <tr> <td>Catégorie : </td> <td style=\"text-align: right;\"> <select name=\"categorie\" style=\"width: 206px;\"> "; $categories = array('Restaurant', 'Salon de coiffure', 'Sale de bronzage', 'Magasin de vetements', 'Magasin de détail', 'Centre commercial', 'Location Immobilier', 'Autre'); foreach ($categories as $value) { echo '<option value="' . $value . '"'; if ($value == $info['categorie']){ echo ' selected'; } echo '>' . $value . '</option>'; } echo " </select> </td> </tr> <tr> <td>État de l'appel : </td> <td style=\"text-align: right;\"> <select name=\"etat\" style=\"width: 206px;\"> <option value=\"1 - Jamais Appelé\">1 - Jamais Appelé</option> <option value=\"2 - Contact établi\">2 - Contact établi</option> <option value=\"3 - Suspect\">3 - Suspect</option> <option value=\"4 - Prospect\">4 - Prospect</option> <option value=\"5 - Interessé\">5 - Interessé</option> <option value=\"6 - Gagné\">6 - Gagné</option> </select> </td> </tr> "; } ?> so I want the <select> named "categorie" to preselect the value contained in DB. Right the selectbox is displaying but not select the correct value (always selecting the first value...) If anyone can help, it would be really appreciated! Thnaks Link to comment https://forums.phpfreaks.com/topic/201791-problem-with-array-selectbox-please-help/ Share on other sites More sharing options...
Pikachu2000 Posted May 14, 2010 Share Posted May 14, 2010 echo "selected=\"selected\""; Link to comment https://forums.phpfreaks.com/topic/201791-problem-with-array-selectbox-please-help/#findComment-1058517 Share on other sites More sharing options...
patheticsam Posted May 14, 2010 Author Share Posted May 14, 2010 LOL! thanks it wokred! Link to comment https://forums.phpfreaks.com/topic/201791-problem-with-array-selectbox-please-help/#findComment-1058518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.