Jump to content

Problem with Array / Selectbox, please help!


patheticsam

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.