🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #3333

Re: php variables dianmicas

#3333
From: Rickoj
Date: Sun, 20 Mar 2005 23:14
110 lines
4822 bytes
En las news:Xns961FBD204747Fjmsnews@200.27.221.71, a Jos� Miguel Santib��ez
se le ocurrio
tipear:
> En el cap�tulo anterior (news:d1kjcf$7ef$1@news1.nivel5.cl), "Rick_oj"
> <rick_oj@[sin-esto]tutopia.com> dijo:
>
>> tengo una duda de una pagina estoy recogiendo X valor, y a la pagina
>> que llega crea X campos de texto, luego envia a otra pagina los
>> valores, pero no se como  crear X variables, es decir si de un campo
>> de texto de un formulario recibo un 2, en la pagina siguiente se
>> crearan 2*2 campos, luego deseo crear 2*2 variables de forma dinamica,
>> pero no se me ocurre como, me dijeron algo con arreglos pero no se si
>> se pueda usar arreglos en algo asi
>>
>> tengo algo asi
>>
>> <?$total=$_POST['numero'];? //este lo recibo de una pagina 1
>>
>> //esta es la pagina 2
>> <form name="formulario" method="post" action="pagina3.php">
>>   <?
>> for($i=1 ; $i<$total+1 ; $i++)
>> {
>>>
>>       <input type="text" name="campo<? echo"$i" ?>">
>>      <input type="text" name="valor<? echo"$i" ?>">
>>     <?
>> }
>>>
>>
>> //pagina 3
>> entonces en esta pagina tendria $variable1=$_POST['campo1'];
>> $variable2=$_POST['campo2']; $variable3=$_POST['valor1'];
>> $variable4=$_POST['valor2'];
>> como podria hacer esto? espero que se entienda
>>
>>
>>
>>
>
> Como una vez hice algo parecido, te transcribo parte del c�digo:
>
> p1.html
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
> <html><body>
>  <form action=p2.php>
>    Ingrese nombre Tabla:
>    <input type=text name=tabla>
>    Ingrese n�mero de campos:
>    <input type=text name=cantidad>
>    <input type=submit value=ingresar>
>  </form>
> </body></html>
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
>
> p2.php
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
> <html><body>
>  <form action=p3.php>
>    <? $tabla = $_REQUEST["tabla"];
>       $cantidad = $_REQUEST["cantidad"];
>       echo "<input type=hidden name=tabla value=$tabla>\n";
>       echo "<input type=hidden name=cantidad value=$cantidad>\n";
>       for ($i = 0; $i < $cantidad; $i++) {
>         echo "<input type=text name=campo$i><p>\n";
>         // este debiera ser un campo de tipo select
>         echo "<input type=text name=tipo$i><p>\n";
>         echo "<input type=text name=largo$i><p>\n";
>       }
>>
>    <input type=submit value=Continuar>
>  </form>
> </body></html>
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
>
> p3.php
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
> <html><body>
>   <h1>Los valores son:</h1>
>    <? $tabla = $_REQUEST["tabla"];
>       $cantidad = $_REQUEST["cantidad"];
>       // $sql = "CREATE TABLE $tabla ("
>       for ($i = 0; $i < $cantidad; $i++) {
>         // if ($i) $sql .= ',';
>         // $sql .= $_REQUEST["campo$i"] . " " .
>         // $_REQUEST["tipo$i"];
>         // if (strlen($_REQUEST["largo$i"])
>         //   $sql .= "(" . $_REQUEST["largo$i"] . ")";
>         echo "Campo: " . $_REQUEST["campo$i"];
>         echo "Tipo: " . $_REQUEST["tipo$i"];
>         echo "Largo: " . $_REQUEST["largo$i"] . "<p>\n";
>       }
>       // $sql .= ')';
>>
> </body></html>
> --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
>
> Espero que te ayude m�s que el muy cr�ptico mensaje de ayer...
>
> si descomentas las l�nas del $sql, debiera tener parte del c�digo de
> creaci�n de una tabla, aunque de memoria no estoy del todo seguro...

algo asi es lo que quiero hacer, para el caso de crear la variables
dinamicamente deberia usar arreglo algo asi como esto?

       for ($i = 0; $i < $cantidad; $i++) {
         $variable1[$i]=$_REQUEST["campo$i"];
         $variable2[$i]=$_REQUEST["tipo$i"];
         $variable3[$i]=$_REQUEST["largo$i"];
       }
Technical Details
Message-ID: <d1l07t$aiv$1@news1.nivel5.cl>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!not-for-mail
References: <d1kjcf$7ef$1@news1.nivel5.cl> <Xns961FBD204747Fjmsnews@200.27.221.71>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,217afd57e2caed0a
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!not-for-mail
From: "Rick_oj" <rick_oj@[sin-esto]tutopia.com>
Newsgroups: chile.comp.programacion
Subject: Re: php variables dianmicas
Date: Sun, 20 Mar 2005 19:14:52 -0400
Organization: Varios
Lines: 115
Message-ID: <d1l07t$aiv$1@news1.nivel5.cl>
References: <d1kjcf$7ef$1@news1.nivel5.cl> <Xns961FBD204747Fjmsnews@200.27.221.71>
NNTP-Posting-Host: pc-154-157-104-200.cm.vtr.net
X-Trace: news1.nivel5.cl 1111360574 10847 200.104.157.154 (20 Mar 2005 23:16:14 GMT)
X-Complaints-To: news@news1.nivel5.cl
NNTP-Posting-Date: Sun, 20 Mar 2005 23:16:14 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1478
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478