NYCPHP Meetup

NYPHP.org

[nycphp-talk] need some form help...

Hans Zaunere zaunere at yahoo.com
Mon May 26 14:09:37 EDT 2003


--- jfreeman at amnh.org wrote:
> Good morning everyone.  Thanks so much for all of your help so far.  I am 
> learning a lot...  but.. I'm stuck again.
> 
> As you prolly know, I'm building a LAMP app. for some scientists who are
> doing 
> a survey of 1000 wasps nests.
> 
> I have the form completed.  For all the parts of the form that involve
> drop-
> down lists, I have working code that goes into a table and grabs the rows
> in 
> the table to build the drop down list in the form.
> 
> Checkboxes and radio buttons are hard coded into the form ... I'd like to
> be 
> able to have those be built dynamically as well, using rows from various 
> tables in the database but I can't figure that one out yet...
> 
> Here's a code snippet of what I use to build the drop downs:
> 
> ---------------snip--------------
> <?php
>     $query = mysql_query("select * FROM author");
> 
> 
> echo "select name=\\"Array[author]\\">
>     <option value=\\"\\">--select author--</option>\
;
> while  ($row = mysql_fetch_row($query)) {
>        print  "<option value=\\$row[0]\\">$row[1]</option>\
";
>      }
> print ("</select>");
> 
> --------------snip----------------
> 
> so.. this works in terms of building the drop down list.  I have no idea 
> whether it will work with an insert statement so that, once I've built the 
> entire POST array from the form, whatever value the surveyor chooses from
> the 
> drop down list will be inserted in the right place in the database.

If I understand correctly, the answer is no.  You can never trust that a row
will be inserted into a database where you expect.  If you need things to be
returned in a consistently ordered manner, you'll need ORDER BY  (ie, ORDER
BY authorname per above).  If alphabetical sorting isn't what you need, you
have to maintain another column (preferably numeric) that you can sort
against.

> I'm COMPLETELY lost with regards to how to use the name=Array[blah-blah] 
> construct when it comes to checkboxes and radio buttons...
> 
> what do I do with the 'value="somevalue"' part of the checkbox or radio 
> button?  where does that go with regards to the Array[blah-blah] part?

<input type=checkbox name="thischeckbox[]" value="The First Value">
<input type=checkbox name="thischeckbox[]" value="The Second Value">

will be accessible in PHP as $_POST['thischeckbox'][0] and
$_POST['thischeckbox'][1], for instance.  Or you can set the array's element
name yourself:

<input type=checkbox name="thischeckbox[one]" value="The First V">
<input type=checkbox name="thischeckbox[two]" value="The Second V">

will end up akin to $_POST['thischeckbox']['one'] and so on in PHP.

> Another point of confusion... one of the fields in the survey form 
> is 'survey_date'.
> 
> I have field of type 'date' in my 'specimen' table... I'd like to have 
> the 'survey_date' be handled automagically for the surveyor by PHP and
> MySQL.. 
> any suggestions on how best to accomplish that?

I just wrote a pCom for this: http://pcoms.net/datetime

I use at some of my sites very successfully, however that particular pCom
isn't complete yet (and I'm working on the site as we speak), so it may not
help much.

H


> 
> There's more help that I need but this is a relatively digestible chunk..
> 
> Thanks folks!
> 
> J.
> 
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 




More information about the talk mailing list