Submit a php table with input boxes

I’ve really been racking my brain with this. I’ll try to explain it to the best of my ability. It is mainly a data entry form.

First, there are three variables to start with. One is an array of regions (NYC, DC, etc) and the other to is a starting date (ex: 01/01/2012) and an ending date (ex: 1/15/2012)

In previous pages, the user selected the number of regions, selected the starting date to start recording, and the ending date. The intent is to enter ‘points’ and the dates are basically by week.

This is what the form is supposed to look like:

In the boxes aside from the first column and first row, they are all input boxes. So, each input box is associated with the value at each end of the table (for example, the box next to NYC and under 01/01/2012 would enter data for NYC in the date range from 01/01/2012 to 01/08/2012).

My question is: How do I go about building this? Should I use a big 2d array? How would the submit button know which input boxes correspond to which date/region? My initial thought is maybe a hidden value that’s like $array[0][x], $array[x][0], but I’m not sure.

I’m not really good at explaining, so I apologize in advance if anyone can’t understand what I’m asking.

Try this:

// hard coding these values for example
// but for OP's case these might be coming from a previous page
$date_array = Array("01/01/2012", "01/08/2012", "01/15/2012");
$region_array = Array("NYC", "DC");

Now generate that form/table in your image like this:

<?php foreach ($date_array as $date){ echo ""; } ?> <?php foreach ($region_array as $region){ echo ""; echo ""; foreach ($date_array as $date){ echo ""; } echo ""; } ?>

now for submit_form.php:

if (isset($_POST['submit'])){
    foreach ($_POST as $k=>$v){
        if ($k != "submit"){
            // split the form input on _
            $input = explode("_", $k);
            echo "
City: " . $input[0]; echo "
Date: " . $input[1]; echo "
Value: " . $v; } } }
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Submit a php table with input boxes

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录