|
Posted by shubeer on 07/14/06 14:19
I seem to have got my knickers in a knot and posted some incorrect
code. Well, this is actually how I would have written the code:
<?php
1: mysql_connect("localhost", "uname", "pword") or die("Died
connecting");
2: mysql_select_db("test");
3: $res=mysql_query("SELECT id, value FROM test_table") or die("Query
failed");
4: print "<select name='jobname'>".
5: "<option selected='selected'>Choose One</option>";
6: while($row = mysql_fetch_assoc($res)) {
7: print "<option value='{$row[id]}'>{$row[value]}</option>";
8: }
9: print "</select>";
10:mysql_close();
?>
As mentioned, we could also add further error checking to this code,
but this is just to illustrate the point. Also, it's not exactly the
same code you posted, but it tries to accomplish the same thing.
With previous experience if the $row[id] is changed to $row[ID] this
will not give the intended result, therefore your index into the $row
associative array must match the columns returned by your query exactly
(yes, including case)
Navigation:
[Reply to this message]
|