donglingyi4679 2013-12-18 22:55
浏览 34
已采纳

PHP制作动态变量和查询

So I hava a problem. On client side users insert theris data in textbox, radio in textarea. All number of input is stored in hidden type, sove php script on my server side knows how many input does it has. Sometimes there is just 20 inputs, sometimes 25 or 30, so the holl stuf is daynamic.

I have two questions: 1. How on server side dynamic generate variables and use them as $input1, $input2 and os on. 2. Let's say that I have somehow managde first problem so my second question is how to make query which sometimes uses only 20 parameters, sometimes 25 and so on. I don't wanna use arrays and tables;

I stareted php code:

 for($i=1;$i<=$num; $i++){    //I get num from a hidden type
        ${"question".$i}="j";
     if(isset($_POST["${"question".$i}"])){
    ${"question".$i}=$_POST[${"question".$i}];
         echo question1;  //this doesn't work but I want make created variables 
                          //to use like this
     }
     else
     {
         echo "You have error with reading ".$i." question";
     }

}

  • 写回答

2条回答 默认 最新

  • doumaoao0182 2013-12-18 22:59
    关注

    Why would you like to use the variables like this? If the input is dynamic use it like an array! -> Easier and cleaner.

    There is good example how to handle a dynamic array input: Post array from html to php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集