RE: usr VAR value as a VAR Name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> This is an example
> page1.php
> =======================================
> <form action="/page2.php?form=yes" method="post">
> $sql_pro ="SELECT Sid FROM table";
> $res_pro = @mysql_query( $sql_pro);
>   while ($campo_pro = @mysql_fetch_array($res_pro)) {
>       $sid_pro = $campo_pro["Sid"];  //  *sid_pro = 4*
>       $sid_pro = 'p'.$sid_pro;     // I'm trying to use de value of 
> $sid_pro as a VAR name *$sid_pro = p4*
>       print "<td > *<input name='$sid_pro' type= 'radio'  
> value='SOLVE_ME'/>* </td>";  // *name=p4 *
>        BLA BLA BLA
>    }

Change to: print "<td > *<input name='".$sid_pro."' type....

And this will give your input radio button a name of whatever $sid_pro is.

Let's say that is 'myradio'

Then your form will render like 
<td > *<input name='myradio' type....

Whent the form is submitted, you would check $_POST['myradio']  (or
$_GET['myradio'])

I think there is a flaw with your logic though, as RADIO buttons must ALL be
named the same thing in a group of them and you would use the VALUE portion
instead. (only one radio button may be selected)

You could use a CHECKBOX if each one is to have a different $sid_pro name
however.

> page2.php
> =======================================
> $sqlname = "SELECT Sid FROM Table";
> $res = mysql_query ($sqlname) ;
> while ($campo_pro = mysql_fetch_array($res)) {
>        $name1 = $campo_pro["Sid"];  // *$name1 = 4*
>        $radio = '$'.'p'.$name1 ; // *$radio = $p4
>        ----------------------
>        Now the Problem
>        **How can I get the Value SOLVE_ME  from the submited form ?*
>    }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux