PHP,使用TextBox提交二维表以进行处理 [英] PHP, Submitting a two dimensional table with TextBox to proccess

查看:31
本文介绍了PHP,使用TextBox提交二维表以进行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个具有动态表的应用程序,每次您打开页面表的行和列时,都会根据数据库中的数据进行更改。
每行是一个卖方公司,每个列是一个项目标题。所有这些供应商都提供相同的商品,因此该表中每个都有一个文本框,每个文本框都包含一个文本框,因此用户可以键入该值,该值表示他们想要从该供应商处获得的水果量。以下是示例。

I am building an application which has a dynamic table, everytime you open the page table`s row and columns changes based on data in database. Each Row is a vendor company each colomn is a Item Title. All these vendors upply the same item, So this table has a textbox in each contains a TextBox so user can type the value, which represents the amount of fruit they want from that supplier. the following is the example.

所以我现在需要做的是,输入这些值之后,我想通过PHP处理它们,然后在确认页面上看到4个不同的报告,例如:写下公司名称,并在其下写下他们必须提供的每项物品,然后是下一家公司的名称,依此类推,直到最后。

So what I need to do now is, after entering these values, I'd like to process them through PHP, and then see 4 different reports at the confirm page, example: write the Company name and under that, what they have to supply for each item, then the next company, so on and so forth to the end.

我不知道是否应该为每个文本框创建不同的类吗?或给他们编号!我应该排列它们吗?我很困惑..如果你们中的任何一个可以帮助您,那就太好了

I don't know if i should create different class for each textbox? or ID them!! SHould I Array them? I am confused.. If any of you guys can help, would be wonderful

非常感谢

推荐答案

我建议您仅将输入元素命名为数组。

I would suggest you just name the input elements as an array. something like:

<input type="text" name="fruits[company1][apple]">
<input type="text" name="fruits[company1][berries]">
<input type="text" name="fruits[company1][orange]">
<input type="text" name="fruits[company1][bannana]">

<input type="text" name="fruits[company2][apple]">
<input type="text" name="fruits[company2][berries]">
<input type="text" name="fruits[company2][orange]">
<input type="text" name="fruits[company2][bannana]">

还是同一件事,第一层是水果,第二层是公司名称。这确实是同一件事,并且通常两者都容易使用。仅取决于您发布表单后如何遍历数据。您最好也使用ID作为公司名称和/或水果。就是这样,例如,带空格的公司名称仍然有效。

or the same thing with the fruit being the first level and company name being second. It is really the same thing and generally just as easy to use either one. Just depends on how you want to loop over the data once you post the form. You might be better off also using ids for the company name and/or the fruit. Just makes it so, for example, company names with a space are still valid.

使用上面的表格,您可以使用以下方式处理数据:

Using the above form, you can process the data with something like this:

<?php
foreach($_POST['fruits'] as $company=>$row){
    foreach($row as $fruit=>$quantity){
        if(!is_numeric($quantity) || $quantity < 0){
            $quantity = 0;
        }
        echo "You selected {$quantity} {$fruit} from {$company}";
    }
}

这篇关于PHP,使用TextBox提交二维表以进行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆