Re: Challenge: MySql result to drop down box
- From: "shubeer" <shubeer@xxxxxxxxx>
- Date: 14 Jul 2006 07:19:44 -0700
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)
.
- References:
- Challenge: MySql result to drop down box
- From: Jim S
- Re: Challenge: MySql result to drop down box
- From: Rik
- Re: Challenge: MySql result to drop down box
- From: Rik
- Re: Challenge: MySql result to drop down box
- From: Jim S
- Re: Challenge: MySql result to drop down box
- From: shubeer
- Challenge: MySql result to drop down box
- Prev by Date: Re: Apache send mail and php
- Next by Date: "call to undefined function" mysql_error when adding new rows to table
- Previous by thread: Re: Challenge: MySql result to drop down box
- Next by thread: Re: Challenge: MySql result to drop down box
- Index(es):
Relevant Pages
|