2014-02-28 27 views
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[][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:在php中創建多維html輸入數組,併發布

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 

我需要一個類似的數組,但我不知道現在怎麼樣。

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 
     ) 

回答

1

您將每個表單輸入作爲主數組中的獨立元素獲取的原因是因爲:name="form[][idnap]"。您在主陣列中創建了一個新項目[],然後將一個陣列密鑰添加到項目與[idnap]

嘗試這樣:

$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++; 
} 
+0

可以選擇你想要的代碼來實現你編輯您的評論格式化文本代碼(前綴爲4個空格每行),並解釋一下呢?這可能是值得你開啓這個新問題的。 –

+0

好,我在最近幾分鐘就發現它,但我還有一個問題:如何在JavaScript中使用它,類似於: 'code' var myControls = document.hozzaado.elements [「form [] [idnap]」]如果(!myControls.length)myControls = [myControls] for(var i = 0; i Woodyka