Hello
I'm new to all this and need some help with arrays......
I've created a wedding gift list form where users can select various gifts from checkboxes and select fields. The code below prints out which gifts have been chosen from the database. It gives the user the subtotal for each gift from the database expressed in the variable $subtotal.
The problem i have now is getting each instance of the variable $subtotal so i can give a total price at the end. As this is in a while loop when I have tried to create an array for $subtotal i only get the last value.
I need a way of getting each value of $subtotal from the while loop.
I hope this makes sense!!
Here is the code......
PHP Code:
include ('connect2.inc');
//check for array
if (is_array ($_POST['select'])) {
// check against database for each item in array
foreach ($_POST['select'] as $gift) {
$sql = "select * from giftlist where gift_id = $gift";
$get_list_res = mysql_query($sql) or die(mysql_error());
while ($recs = mysql_fetch_array($get_list_res)) {
//variables from database
$id = $recs['gift_id'];
$title =$recs['title'];
$details =$recs['details'];
$quantity =$recs['quantity'];
$price=$recs['price'];
$total=$recs['total'];
// grabs amount from $id variable
$amount = $_POST[$id];
// I need each variable of $subtotal below so I can create a total price at end
$subtotal= $price * $amount;
print "Gift $title Price= $amount X $price = £$subtotal<br>\n";
}
}
} else {
print 'Please select some gifts from the list';
}
I am getting close to throwing my laptop out the window so please help!
Thanks
Last edited by davedark; 06-29-2005 at 10:36 AM..
|