Jump to content

Archived

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

whare

<option> problem

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

Share this post


Link to post
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]

Share this post


Link to post
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 :).

Share this post


Link to post
Share on other sites

×

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.