Jump to content

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


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>";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.