Re: Challenge: MySql result to drop down box



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)

.



Relevant Pages

  • Re: Xilinx FPGAs in battery-powered scenarios
    ... No knickers in a knot. ... Some people think that sleep mode or idle mode ... Power down to me has always ...
    (comp.arch.fpga)
  • Re: [PHP] plugging gmmktime value into gmdate yields incorrect date
    ... [PHP] plugging gmmktime value into gmdate yields incorrect ... On two of the servers, I got 03, 23, 2000 back. ...
    (php.general)
  • Re: Forgeries and fools----->Re: Israel is above
    ... propaganda used by the German Nazis. ... The old hag has had her extra large knickers in a knot for the past three ...
    (uk.politics.misc)
  • Re: Obama to Seek New Assault Weapons Ban
    ... My knickers are fine. ... Ok I won't include you but certainly others are getting their knickers in a knot. ... We can only buy fully automatic weapons with special permits. ... The "assault rifle ban", among other things, banned no assault rifles. ...
    (rec.scuba)
  • Re: strong/weak typing and pointers
    ... >> response given the PHP language definition. ... > create explicit language constructs to do the trick. ... agree what's correct or incorrect for every example, so we have to take the ... language definition as the measuring stick for correct or incorrect. ...
    (comp.lang.python)