html dropdown list in php from mysql
Posted: Sun Oct 18, 2009 10:09 pm
OK, I found a bunch of examples of doing this, but I'm missing something. I want to create a dropdown list for a user to select a lastname from a list...
select id, lastname from mytable
this gets me 10 lastnames, each with a unique id.
$options = "";
loop and build the string of "option id" stuff...
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
$ln=$row["LastName"];
echo "<br> id = " . $id . " and " . $ln;
THIS echo above, works fine... I get each id and lastname perfectly. So apparently they are coming back from
the query, and are getting put in the local variables.....
$options .= "<option value =" . $id . ">" . $ln . "</option>\n";
print "<br> option list is " . $options;
}
I've tried echo and print. In both cases what I get is
option list is Allen Anderson Andrews Benson Bergmann Bergstrom Best Blocker
INSTEAD of
option list is <option value = "111">Allen</option>
<option value = "112">Anderson</option>
and so on.......
What is my php doing to me? And how do I make it NOT?
select id, lastname from mytable
this gets me 10 lastnames, each with a unique id.
$options = "";
loop and build the string of "option id" stuff...
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
$ln=$row["LastName"];
echo "<br> id = " . $id . " and " . $ln;
THIS echo above, works fine... I get each id and lastname perfectly. So apparently they are coming back from
the query, and are getting put in the local variables.....
$options .= "<option value =" . $id . ">" . $ln . "</option>\n";
print "<br> option list is " . $options;
}
I've tried echo and print. In both cases what I get is
option list is Allen Anderson Andrews Benson Bergmann Bergstrom Best Blocker
INSTEAD of
option list is <option value = "111">Allen</option>
<option value = "112">Anderson</option>
and so on.......
What is my php doing to me? And how do I make it NOT?