|
Posted by J.O. Aho on 01/18/07 11:14
Geert-Jan van Leeuwen wrote:
>
> I am using the html <select>-<option> code to select options i read from
> mysql:
>
> echo "<select name=status> ";
>
> $query = veilige_query("
> select id, status
> from status
> order by id
> ");
> while ($regel = mysql_fetch_array ($query))
> {
> echo "<option value=" . $regel["status"] . ">" .
> $regel["status"];
> }
> echo "</select>";
>
>
>
> If in an option there are spaces it only returns the part until the space.
> For example:
> The mysql table has a value "In public". On the html-page I see "In
> public", the returned result is: "In". So it skipped everything after
> the space. When I read values using
> <input type=text name=so-and-so>
> it reads everything allright.
>
> I am missing something in php. What am i doing wrong?
If you are using
<input type=text name=so and so>
then HTML will see it as input-tag with "type=text", "name=so", "and" and
"so", where the two last options are completely unknown for HTML.
So see to always double quote the values for each option (single quote is ok
by HTML standards, but not all browsers handles that well). Don't forget that
many HTML-tags has an start and stop tag, you need to include those stop-tags too.
<input type="text" name="so and so">
Those:
echo "<select name=\"status\"> ";
/* naming a column and a table the same, really bad */
$query = veilige_query("SELECT id, status FROM status ORDER BY id");
while ($regel = mysql_fetch_array($query)) {
// Don't forget to close your HTML tags
// Using the id as value uses less space and you don't have to
// look up the id when you have to search for it in another table
echo "<option value=\"{$regel['id']}\">{$regel['status']}</option>";
}
echo "</select>";
A good page to visit is http://validator.w3.org/
--
//Aho
Navigation:
[Reply to this message]
|