Your welcome, I hope it is to use for you.
Today I looked at phpmyadmin and they indeed send post arrays.
In your form it would look like this.
HTML Code:
<form action="" method="post">
<!-- row 1 -->
<input type="text" name="name[1]" value="row1name" />
<input type="text" name="date[1]" value="row1date" />
<input type="text" name="address[1]" value="row1address" />
<!-- row 2 -->
<input type="text" name="name[2]" value="row2name" />
<input type="text" name="date[2]" value="row2date" />
<input type="text" name="address[2]" value="row2address" />
<!-- row 3 -->
<input type="text" name="name[3]" value="row3name" />
<input type="text" name="date[3]" value="row3date" />
<input type="text" name="address[3]" value="row3address" />
<!-- row 4 -->
<input type="text" name="name[4]" value="row4name" />
<input type="text" name="date[4]" value="row4date" />
<input type="text" name="address[4]" value="row4address" />
</form>
In your PHP you can do something like
PHP Code:
foreach($_POST['name'] as $key => $value)
{
//Here you can execute functions or query on every post
$db->query('UPDATE yourtable SET name = "'.$_POST['name'][$key].'", date = "'.$_POST['date'][$key].'", address = "'.$_POST['address'][$key].'" WHERE id = '.$key);
}
If it are new rows you are adding then you can leave the id out of your post arrays.
HTML Code:
<form action="" method="post">
<!-- row 1 -->
<input type="text" name="name[]" value="row1name" />
<input type="text" name="date[]" value="row1date" />
<input type="text" name="address[]" value="row1address" />
<!-- row 2 -->
<input type="text" name="name[]" value="row2name" />
<input type="text" name="date[]" value="row2date" />
<input type="text" name="address[]" value="row2address" />
<!-- row 3 -->
<input type="text" name="name[]" value="row3name" />
<input type="text" name="date[]" value="row3date" />
<input type="text" name="address[]" value="row3address" />
<!-- row 4 -->
<input type="text" name="name[]" value="row4name" />
<input type="text" name="date[]" value="row4date" />
<input type="text" name="address[]" value="row4address" />
</form>
If you want to delete all the selected rows, you can use 1 query and do the where id IN(1,2,3,4,etc...). This is also valid if you i.e. update the name of multiple rows with the same value.
But whenever you update multiple rows where each has his own values, you are forced to create multiple querys I believe.
I think maybe you can build your form also this way. But don't know for sure. You'll have to try it out.
HTML Code:
<form action="" method="post">
<!-- row 1 -->
<input type="text" name="row[1][name]" value="row1name" />
<input type="text" name="row[1][date]" value="row1date" />
<input type="text" name="row[1][address]" value="row1address" />
<!-- row 2 -->
<input type="text" name="row[2][name]" value="row2name" />
<input type="text" name="row[2][date]" value="row2date" />
<input type="text" name="row[2][address]" value="row2address" />
<!-- row 3 -->
<input type="text" name="row[3][name]" value="row3name" />
<input type="text" name="row[3][date]" value="row3date" />
<input type="text" name="row[3][address]" value="row3address" />
<!-- row 4 -->
<input type="text" name="row[4][name]" value="row4name" />
<input type="text" name="row[4][date]" value="row4date" />
<input type="text" name="row[4][address]" value="row4address" />
</form>
Php would be like this I guess:
PHP Code:
foreach($_POST['row'] as $key => $values)
{
//Here you can execute functions or query on every post
$db->query('UPDATE yourtable SET name = "'.$values['name'].'", date = "'.$values['date'].'", address = "'.$values['address'].'" WHERE id = '.$key);
}
Bookmarks