多维html输入数组在PHP中创建,并发布 [英] Multidimensional html input array create in php, and post

查看:168
本文介绍了多维html输入数组在PHP中创建,并发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while($eredmeny = mssql_fetch_assoc($result))
{   
$table_results  = '<tr style="color: #000e94; font-size=12" align="center" valign="middle">';
$table_results .= '<td>';
$table_results .= "<input type='checkbox' name='form[][id]' id='form[][id]' value='{$eredmeny['ID']}'>"; 
$table_results .= '</td>';
$table_results .= '<td><input type="text" name="form[][idnap]" id="form[][idnap]" value="' . $eredmeny['ID'] .'" style="width:130px;"></td>';   
$table_results .= '<td><input type="text" name="form[][feladat]" id="form[][feladat]" value="' . $eredmeny['Feladat'] .'" style="width:130px;"></DIV></td>';
$table_results .= '<td><b><input type="text" name="form[][hatarnap]" id="form[][hatarnap]" value="' . date_format(date_create($eredmeny['Hatarido_alap']), 'd') .'" style="width:20px;">nap</b>';
$table_results .= '<input type="text" name="form[][hatarora]" id="form[][hatarora]" value="' . date_format(date_create($eredmeny['Hatarido_alap']), 'H:i:s') . '" style="width:55px;"></td>';
$table_results .= '<td>' . $eredmeny['Tipusa'] . '</td>';
$table_results .= '</tr>';
echo $table_results;
}

我有这段代码来创建html表单。形式是usabe,很好。我在php中有这样的表单:

I've this code, to create html form. The form is usabe, good. I've got this form in php:

Array
(
    [0] => Array
        (
            [id] => NAPI_01_
        )

    [1] => Array
        (
            [idnap] => NAPI_01_20140220
        )

    [2] => Array
        (
            [feladat] => SM1
        )

    [3] => Array
        (
            [hatarnap] => 01
        )

    [4] => Array
        (
            [hatarora] => 07:15:00

我需要一个类似的数组,但

I need an array similar, but I don't know how now.

Array
(
    [0] => Array
        (
            [id] => NAPI_01_
            [idnap] => NAPI_01_20140220
            [feladat] => SM1
            [hatarnap] => 01
            [hatarora] => 07:15:00
        )
[1] => Array
        (
            [id] => NAPI_01_
            [idnap] => NAPI_01_20140220
            [feladat] => sm2
            [hatarnap] => 01
            [hatarora] => 07:15:00
        )


推荐答案

原因是你将每个表单输入作为主数组中的一个独立元素,原因在于: name =form [] [idnap]。你用 [] 在主数组中创建一个新项目,然后用 [idnap将项目添加到 ]

The reason you're getting each form input as a separate element in the main array is because of this: name="form[][idnap]". You create a new item in your main array with [], then add an array key to that item with [idnap].

试试这样:

Try something like this:

$count = 0;

while($eredmeny = mssql_fetch_assoc($result))
{   
$table_results  = '<tr style="color: #000e94; font-size=12" align="center" valign="middle">';
$table_results .= '<td>';
$table_results .= "<input type='checkbox' name='form[$count][id]' id='form[$count][id]' value='{$eredmeny['ID']}'>"; 
$table_results .= '</td>';
$table_results .= '<td><input type="text" name="form[$count][idnap]" id="form[$count][idnap]" value="' . $eredmeny['ID'] .'" style="width:130px;"></td>';   
$table_results .= '<td><input type="text" name="form[$count][feladat]" id="form[$count][feladat]" value="' . $eredmeny['Feladat'] .'" style="width:130px;"></DIV></td>';
$table_results .= '<td><b><input type="text" name="form[$count][hatarnap]" id="form[$count][hatarnap]" value="' . date_format(date_create($eredmeny['Hatarido_alap']), 'd') .'" style="width:20px;">nap</b>';
$table_results .= '<input type="text" name="form[$count][hatarora]" id="form[$count][hatarora]" value="' . date_format(date_create($eredmeny['Hatarido_alap']), 'H:i:s') . '" style="width:55px;"></td>';
$table_results .= '<td>' . $eredmeny['Tipusa'] . '</td>';
$table_results .= '</tr>';
echo $table_results;
$count++;
}

这篇关于多维html输入数组在PHP中创建,并发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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