Question about dynamically creating a form
| From: | Amanda McComb | Date: | Wed, 16 Apr 2003 20:05:20 +0000 |
| Subject: | Question about dynamically creating a form | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-144188@lists.php.net to get a copy of this message | ||
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