douquejituan938904 2015-09-22 01:37
浏览 20
已采纳

如何在PHP中访问具有未知名称的复选框

I have a MySQL database with auto-increment column "line numbers." In the form that is being submitted to the script, there are check boxes. I don't know how many check boxes there are, because each Customer has a different number of services that they're allowed to access. When the check box is clicked, they've used a service and the integer in column Available for that row needs to decrease by one. Sometimes, the user can say that multiple services were used and more than one row needs to be affected.

Where I'm becoming stuck is on two things: how the check boxes are named, and if I name them by the line number, how to access them with PHP.

while($cell = mysqli_fetch_array($service_details_query)) {
                    echo "</br>";
                    echo "<input type='checkbox' name='" . $cell['line_item'] . "'>";
                }

The above code is how I'm making the check box. Probably the biggest part of the question is how I could better name it so that I can predict what names to look for ($_POST[name]) when the form is submitted (instead of a random number).

The other part I'm getting stuck on is, if I do decide to keep the naming strategy, how to fetch it. What I've thought of is to use a loop to extract the true/false data that's carried, but I don't know how to execute that. Sure, I can write a for or while loop, but I don't know how to extract the name of the object.

  • Is there any way I could carry extra data to a PHP script, other than the name?
  • Is there a better way I could name the check box so that I'm not stuck having to figure out a complicated way of finding the data, retrieving the name, etc.

I'm sort of a beginner when it comes to PHP. I know how to get my way around with for loops, while loops, basic commands such as echo... but I'm really lacking

  • 写回答

4条回答 默认 最新

  • doucheng2053 2015-09-22 02:32
    关注
    while($cell = mysqli_fetch_array($service_details_query)) {
                        echo "</br>";
                        echo "<input type='checkbox' name='checkboxname[]' value ='".$cell['line_item']."'>";
                    }
    

    It should do a $_POST array with the name checkboxname inside that array, you find the values. You can find it threating $_POST['checkboxname'] as an array.

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

报告相同问题?

悬赏问题

  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据