Jump to content


Photo

<option> problem


  • Please log in to reply
4 replies to this topic

#1 whare

whare
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 20 August 2006 - 01:08 AM

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

<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>

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

Any ideas?

Thanx

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 August 2006 - 01:11 AM

Try this:

$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>';


#3 whare

whare
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 20 August 2006 - 01:15 AM

Thanx I will give that a go :)

#4 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 20 August 2006 - 01:17 AM

yea he needed echo

#5 inqztve

inqztve
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 20 August 2006 - 01:23 AM

$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 :).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users