NYCPHP Meetup

NYPHP.org

[nycphp-talk]learning about foreach()

Joshua S. Freeman jfreeman at amnh.org
Wed May 21 15:17:06 EDT 2003


Max,

give yourself a big hand...  you know.. that was creeping around in the back
of my brain at one point but I wasn't sure if that was going to break what I
was trying to do or not.. apparently you hit the nail on the head...

so.. now.. it's building this:

<select name="order"><option value="1">1</option><option
value="1">Hymenoptera</option></select>

so.. i'm close... here's the code I'm using now:


$query= mysql_query("select * FROM taxa_order");

  $result = mysql_fetch_assoc($query);
        print ("<select name=\\"order\\">");
        foreach ($result as $key=>$val)
        print "<option value=\\"1\\">$val</option>";
        print ("</select>");

so.. what do i need to adjust so I get this:

<select name="order"><option value="1">Hymenoptera</option></select>  ?

J.


On 5/21/03 3:10 PM, "max goldberg" <max at idsociety.com> wrote:

> No one seems to have mentioned this, but 'order' is a reserved word in
> MySQL. See http://mysql.tviund.is/doc/en/Reserved_words.html
> 
> -max
> 
> Joshua S. Freeman wrote:
> 
>> I've made a conceptual breakthrough (duh!) with regards to this
> project I'm
>> working on to really get to a meaningful skill level with MySQL/PHP
>> development.  But.. for some reason, I'm really stuck on this one point:
>> 
>> I have a database called 'wasps'.  The database has 19 tables so far
> most of
>> which are 'lookup' tables (is that the right term?)...
>> 
>> The main table in the database is called 'specimens'.  Each 'specimen'
> has a
>> taxonomy (order, family, genus, subgenus, species, subspecies).
>> 
>> For each part of the taxonomy I have a separate table.
>> 
>> Ideally, when someone loads the survey form to begin building a new record
>> in the 'specimens' table, I want to query those taxonomy tables (order,
>> family, genus, etc...) so that I can build
>> <select><option></option></select> menus based on the rows inside each
>> taxonomic table...
>> 
>> I want to do this using 'foreach'...
>> 
>> I've tried a few different things but I can't get it to work:
>> 
>> mysql_connect($host, $user, $password)
>>     or die("Could not connect to database");
>> mysql_select_db($database)
>>     or die ("Could not select $database database");
>> 
>> print "The current database is $database";
>> 
>> $query= mysql_query("select * FROM order");
>> 
>> $result = $query;
>>         print ("<select name=\\"order\\">");
>>         foreach ($result as $key=>$val)
>>         print "<option value=\\"1\\>$val</option>";
>>         print ("</select>");
>>         }
>> 
>> ?>
>> 
>> but this does not work.. i know I'm close.. and I just spent 2 hours at
>> barnes & nobles at a table in the cafe with a bunch of PHP books (couldn't
>> find that WROX book someone suggested earlier)  trying to make this
> work on
>> just the order table because that table only has one record in it...
> but I
>> could not make it work.. if I can figure out how to make this, I'll be
> able
>> to make considerable progress on this thing..
>> 
>> Someone please help me over this hump!
>> 
>> Thanks!
>> 
>> J.
>> 
>> 
>> 
>> 
>> 
>> 
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 
> 




More information about the talk mailing list