Page 1 of 1

multiple array and form processing

Posted: Sat Mar 20, 2004 6:40 am
by NateVeronica
Hi all, I know it's my first post.. dont burn me :twisted:

Look, I have a form with 5 input fields (within a while .. loop) that holds data from a database. So there are X repeats depending on how many rows are in the database.

So what I want to do is use a foreach statement that cycle through the form data so I can update the database (matching the original rows from the database/form)

Could someone help me??

With the form, the $_POST array holds the data like ..
(input1 => Array, input2 => Array etc..)

So how would I get the array data to just output like I have the form setup.. with all its rows etc.
Row 1 ( input1, input2, input3 etc)
Row 2 ( input etc..)

Do you understand what I mean??

Posted: Sat Mar 20, 2004 6:52 am
by m3mn0n
Have you tried using hidden fields to place data that you want to update again? Or if the information is sensitive, why not recall it on the form handling page and then update it there?

Posted: Sat Mar 20, 2004 7:00 am
by NateVeronica
oh yeah, sorry I did try using a hidden field in the form that held the database ID, which I then counted and used as a key as a way of extracting the array data. (is this the most efficient way???)

I also tried:

foreach ($_POST as $key => $val) {
echo $key . " ". $val;
echo "<br>";
foreach ($_POST[$key] as $value) {
echo $value;
echo "<br>";
}
}

But it doesn't put all the data together. My problem with the hidden field is that if I were to use the same code to insert data from a blank field, then there would be no ID from database. Sorta trying to ensure there is little redundant code.

Posted: Sat Mar 20, 2004 5:26 pm
by NateVeronica
bump

Posted: Sun Mar 21, 2004 3:29 am
by NateVeronica
I solved the problem..

$iNum = count($_POST['formvariable]);

for ($i=0; $i<$iNum; $i++) {
foreach ($_POST as $k => $v) {
print $k . " " . $v[$i];
}
}