I am attempting to create a form that allows me to change details on
certain products such as price etc.
In the form I have 4 textfields that are repeated for however many
products are in a particular category. The textfields contain:
cap_id - the index value field
price - the price of the product
percentage_discount - the percentage discount to put into the product
record
monetary discount - the amount of money to put into the product record
set_price - the price to override the percentage and monetary amount to
display on the website.
Each of the textfields is defined using the [] to create an array to
access from the post variables.
On the page that the form submits to I've managed to get the 4 values
for each record into seperate arrays using implode and explode:
<?php
$cap_id_to_update = implode(' ', $POST['cap_id']);
$cap_id_array = explode(' ', $cap_id_to_update);
$set_price_to_update = implode(' ', $_POST['set_price']);
$set_price_array = explode(' ', $set_price_to_update);
$percentage_discount_to_update = implode(' ',
$POST['percentage_discount']);
$percentage_array = explode(' ', $percentage_discount_to_update);
$monetary_discount_to_update = implode(' ',
$POST['monetary_discount']);
$monetary_array = explode(' ', $monetary_discount_to_update);
?>
I want to get the arrays into one multidimensional array so that I can
loop through the array and output suitable mysql update statements that
can be executed to update the table.
I basically need it to be of the format:
<?php
$updatestatements = array(
"Field[n]" => array ("$cap_id", "$percentage_discount",
"$monetary_discount", "$set_price"),
)
// output the mysql commands
foreach (---- => -----){
echo($updatestatement);
// create the mysql update sql and execute
@($updatestatement)
}
?>
Where n is next empty array value and
<?php
$cap_id
$percentage_discount
$monetary_discount
$set_price
?>
are the appropriate values from the arrays created.
I would (hopefully) assume that it's a case of looping using foreach
through the array 4 times and inserting the correct value into the
correct array section.
But after much hair pulling out I'm still no closer to a solution.
Anyone got any ideas?