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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度