动态post变量的php while循环

动态post变量的php while循环,php,Php,上一页(添加为编辑) 它起作用了 <?php $scriptot = ($_POST["ohyeah"]);// working $y = 1; $x = 1; $r= 1; while($x <= $scriptot ) {//working ${"equip".$x} = ($_POST["equip".$x]); //not working echo ${"equip" .$x};//not working $x++; // working } 出于组织目的

上一页(添加为编辑)

它起作用了

<?php



$scriptot = ($_POST["ohyeah"]);// working
$y = 1;
$x = 1;
$r= 1;

while($x <= $scriptot ) {//working

 ${"equip".$x} = ($_POST["equip".$x]); //not working
 echo ${"equip" .$x};//not working
 $x++; // working
 }

出于组织目的,您应该真正使用数组

例如,在表单中,您可以将输入名称设置为“equip[1]”,该值将作为
$\u POST['equip'][1]
导入PHP。然后您可以运行:

foreach($_POST['equip'] as $key=>$value) {
   # where $key = 1, the $value will be of equip[1]
}
可能不是你想要的,但它似乎比你正在尝试的更干净。

我就是这样尝试的

<?php while ( have_posts() ) : the_post(); ?>
           
     <div class="contentTitle"><?php the_title(); ?></div>
     <div class="contentText">
        <?php the_content(); ?>
    </div>
            
<?php endwhile ?>


你可以说得更具体一些吗?在我上一页的表单中,我动态地创建了输入,并使用递增的名称equip1、equip2。。。我需要将它们插入数据库,但需要唯一的变量来发布它们。我使用$scriptot生成表单,也使用while循环,因此,如果我使用动态帖子,它应该可以工作。我需要一种方法,将所有表单数据动态发布为$scriptot变量variesedit,并使用“上一页”的代码
foreach($_POST['equip'] as $key=>$value) {
   # where $key = 1, the $value will be of equip[1]
}
<?php while ( have_posts() ) : the_post(); ?>
           
     <div class="contentTitle"><?php the_title(); ?></div>
     <div class="contentText">
        <?php the_content(); ?>
    </div>
            
<?php endwhile ?>