RE: [PHP] Question about dynamically creating a form
| From: | Jennifer Goodie | Date: | Wed, 16 Apr 2003 20:09:31 +0000 |
| Subject: | RE: [PHP] Question about dynamically creating a form | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144191@lists.php.net to get a copy of this message | ||
Read the PHP manual section on variable variables
http://www.php.net/manual/en/language.variables.variable.php
Try
$var = $search_result['list_serv_cd'];
echo $var;
if ($$var == 1){
}
> -----Original Message-----
> From: Amanda McComb [mailto:amccomb@indiana.edu]
> Sent: Wednesday, April 16, 2003 1:05 PM
> To: php-general@lists.php.net
> Subject: [PHP] Question about dynamically creating a form
>
>
> 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>