multiple array and form processing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NateVeronica
Forum Newbie
Posts: 8
Joined: Sat Mar 20, 2004 6:40 am

multiple array and form processing

Post 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??
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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?
NateVeronica
Forum Newbie
Posts: 8
Joined: Sat Mar 20, 2004 6:40 am

Post 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.
NateVeronica
Forum Newbie
Posts: 8
Joined: Sat Mar 20, 2004 6:40 am

Post by NateVeronica »

bump
NateVeronica
Forum Newbie
Posts: 8
Joined: Sat Mar 20, 2004 6:40 am

Post 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];
}
}
Post Reply