🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #3331

Re: php variables dianmicas

#3331
From: Jos� Miguel Santib��ez
Date: Sun, 20 Mar 2005 22:35
103 lines
4331 bytes
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...

-- 
                           Jose M. Santiba�ez A.
                             <jms@nivel5.cl>
                           <http://caos.cl/jms>
Technical Details
Message-ID: <Xns961FBD204747Fjmsnews@200.27.221.71>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.kjsl.com!news1.nivel5.cl!news.vcd.cl!not-for-mail
References: <d1kjcf$7ef$1@news1.nivel5.cl>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,217afd57e2caed0a
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII
Newsgroups: chile.comp.programacion
Subject: Re: php variables dianmicas
From: "Jos� Miguel Santib��ez" <jms@nospam.nivel5.cl>
References: <d1kjcf$7ef$1@news1.nivel5.cl>
Organization: Caos Consultores
Message-ID: <Xns961FBD204747Fjmsnews@200.27.221.71>
User-Agent: Xnews/5.04.25
X-Face: +|NgjgFM{<rs%\Q|vUu16]a6,}?MJTA<!PEEI+x&Gw-Gyq+?$}fvo+.(,-r;)~Qzn)#{{nxU,OT?w^s<7m4ckCJ*L$c#I)yHL7b)GdU*#l
NNTP-Posting-Host: 120-92-112.adsl.terra.cl
Date: 20 Mar 2005 19:35:40 -0300
X-Trace: news.vcd.cl!not-for-mail 1111361740 120-92-112.adsl.terra.cl (20 Mar 2005 19:35:40 -0300)
Lines: 103
X-Authenticated-User: jms
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.kjsl.com!news1.nivel5.cl!news.vcd.cl!not-for-mail