Re: Question about dynamically creating a form

From: Date: Wed, 16 Apr 2003 21:15:27 +0000
Subject: Re: Question about dynamically creating a form
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144192@lists.php.net to get a copy of this message
*This message was transferred with a trial version of CommuniGate(tm) Pro* Amanda - One possible way, which is what I do alot, is to set the checkbox <inputs> name field as an array like so... <INPUT
                   TYPE="checkbox"
                   NAME="checkBoxArray[<? echo $search_result['list_serv_cd']; ?>]"
                   SIZE="20"
                   MAXLENGTH="50"
                   VALUE="1">
when the form is posted it will treat the form data where checkBoxArray[xxx] is data as an array which you can then do a foreach($checkBoxArray as $k => $v) { //print the results, error check, insert to database, etc. echo $k.' => '.$v.'<br>'; }; Hope this helps, if you have any questions on it, feel more than welcome to email me directly. Rolf Brusletto rbrusletto@phpexamples.net PHP/MySQL Coder Security Admin www.phpexamples.net Amanda McComb wrote:
*This message was transferred with a trial version of CommuniGate(tm) Pro* ok...so... I am creating a form using fields from a database. For one table, I select everything, loop through, and for each row, I
create a checkbox where the name = primary key, the value = 1, and the    label = whatever the name of the field is.  It looks like this:
      <?$query = "SELECT * FROM list_serv_t WHERE retired_flag is NULL OR
       retired_flag = 0 ORDER BY list_serv_name";
       $search_results = mysql_query($query) or die("Select Failed!"); ?>
       <?while ($search_result = mysql_fetch_array($search_results)) {?>
       <INPUT
                    TYPE="checkbox"
                    NAME="<? echo $search_result['list_serv_cd']; ?>"
                    SIZE="20"
                    MAXLENGTH="50"
                    VALUE="1">  <? echo
                    $search_result['list_serv_name'] ?> <BR>
       <?}?>
Now, that works fine, but how do I get the value out of that so I can error check it or put it in the database? I tried re-creating the name by looping through the table again and making a new variable that contains the name like this: $var = "$"; $var .= $search_result['list_serv_cd']; echo $var; But when I try to test the value: if ($var == 1){ } Obviously, it won't work, because $var == "$22" or whatever the number happens to be. What's the best way to do this? Thanks, Amanda


« previous php.general (#144192) next »