Retrieving data from many form objects in a loop
Posted: Tue Mar 22, 2005 11:29 pm
I have an array that contains the product ID of various products. IE (1,2,34,23,7,12,15,67,234,4)
I parse the database using each array item as a unique ID and retrieve the product info taken from each ID in the array.
When the product info is displayed, it is done so inside a form. The price for each product is displayed in a Text Field box, so if a customer gets a discount, the price may be edited. There could be man Text Field boxes, depending on how many products have been chosen.
I want to then be able to take the product_id and new adjusted prices from each product (if any were adjusted) and use them later for totals, stock control etc, but the problem I'm facing is, the Text Fields are drawn in a loop, and I am unsure of how to retrieve the data. See this code for the problem:
The problem and my question is about the name of the Text Edit box, it is 'adjusted_service_price'. The problem with that is, each of my (say) 10 products will have the same Text Edit box name, hence I will only be able to get the value of the very last one (I presume) and I need to get the values from all of them.
This could be overcome by supplying each Text Edit box with a unique name, ie, make the name value adjusted_service_price
I really hope that makes sense and I really hope someone has some ideas. It's been working this brain of mine over for two days now whilst I work on other things to keep moving but the time has come, it has to be sorted. Any help would be GREATLY appreciated.
I parse the database using each array item as a unique ID and retrieve the product info taken from each ID in the array.
When the product info is displayed, it is done so inside a form. The price for each product is displayed in a Text Field box, so if a customer gets a discount, the price may be edited. There could be man Text Field boxes, depending on how many products have been chosen.
I want to then be able to take the product_id and new adjusted prices from each product (if any were adjusted) and use them later for totals, stock control etc, but the problem I'm facing is, the Text Fields are drawn in a loop, and I am unsure of how to retrieve the data. See this code for the problem:
Code: Select all
foreach($services as $val)
{
$sql = "SELECT * FROM services WHERE id = $val";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$service_id = $Xcontent["id"];
$service_name = $Xcontent["name"];
$service_description = $Xcontent["description"];
$service_price = $Xcontent["price"];
if ($val == $service_id)
{
echo "
<tr>
<td class=\"clientview\"><div align=\"center\">$service_name</div></td>
<td class=\"clientview\"><div align=\"center\">$$service_price</div></td>
<td class=\"clientview\"><div align=\"center\"><input name=\"adjusted_service_price\" type=\"text\" value=\"$service_price\" size=\"3\" maxlength=\"4\"></div></td>
";
}
}This could be overcome by supplying each Text Edit box with a unique name, ie, make the name value adjusted_service_price
I really hope that makes sense and I really hope someone has some ideas. It's been working this brain of mine over for two days now whilst I work on other things to keep moving but the time has come, it has to be sorted. Any help would be GREATLY appreciated.