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;
}

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
        )

1 Answer 1

1

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++;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Can you edit your comment to format the text as code (prefix each line with 4 spaces) and explain a little about what you want the code to achieve? It might be worth you opening this as a new question.
Good, I find it out in recent minutes, but I've another question: How to use it in javascript, similar before: code var myControls = document.hozzaado.elements["form[][idnap]"] if(!myControls.length) myControls = [myControls] for (var i = 0; i < myControls.length; i++) { var ertek=document.getElementById('datum1').value; myControls[i].value = myControls[i].value + ertek.slice(0,4); myControls[i].value = myControls[i].value + ertek.slice(5,7); myControls[i].value = myControls[i].value + ertek.slice(8,10); } – Okay, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.