Jump to content

[SOLVED] Editing via a form populated from MySQL: How do I have the select menu selected?


suttercain

Recommended Posts

Hi guys,

 

I built a small admin panel that allows the user to submit data, via a form. One field is a select menu (html populated). Now when they try to edit the record the form is displayed with the content already filled in to allow editing. But the select menu always goes to the first select. Is there a way to have the select menu already selected to the value from the MySQL row?

 

EXP

Column State will always be CA, AZ or NV. If the record has a value of NV, how do I have that show in the select menu when the user goes to edit the record, with also allowing them to change it to either CA or AZ?

 

Thanks.

 

SC

Bit I would have to do that with an if or switch statement right? What because that solution, as far as I can see, will only work if the value from the MySQL table is test 2. What if it is test 3?

 

SC

basic concept

 

<?php
$TheList = array("test1" => 1, "test2" => 2, "test3" => 3)

echo "<select name='test'>";
foreach($TheList as $K => $V)
{
  $sel = ($V == $_POST['test'])?"selected":"";
  echo "<option value='$V' $sel>$K</option>";
}
echo "</select>";
?>

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.