Jump to content

<option> problem


whare

Recommended Posts

Hi All

right i have been trying to work with dropdown boxes sending the info to a database but the info in the dropdown is also be pulled from the db so when i submit the form it put the php code into the db but not the option so something like this

[code]<select size="1" name="D1">
  <? $result = mysql_query("SELECT * FROM pilot ORDER BY pilotid ASC")
or die(mysql_error()); ?><option value="$row['dbcolum']"><? echo $row['dbcolum']; ?></option>
  </select>[/code]

now that would place into my db $row['dbcolum']; and not the text that it should put in

Any ideas?

Thanx
Link to comment
Share on other sites

Try this:

[code]$result = mysql_query("SELECT * FROM pilot ORDER BY pilotid ASC") or die(mysql_error());
echo '<select size="1" name="D1">';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<option value="' . $row['dbcolum'] . '">' . $row['dbcolum'] . '</option>';
}
echo '</select>';[/code]
Link to comment
Share on other sites

$result = mysql_query("SELECT * FROM pilot ORDER BY pilotid ASC")
$rows = mysql_numrows($result);

$choice = "";
$count = 0;
while($count < $rows)
    {
    $choice = $choice . "<option value=". mysql_result($result, $count, "your_column"). ">". mysql_result($result, $count, "your_column"). "</option>";
    $count++;
    }

<select size="1" name="D1"><?echo $choice; ?></select>

>> Please check for typos :).
Link to comment
Share on other sites

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.