Hello
I'm new to all of this and still having problems with this wedding giftlist I'm creating. I need to pass the variables from the select array and also the relevant quantity so that this info can be stored in a database.
This: print_r ($_POST['select']); prints the correct array contents however
print_r ($amounted); only gives me the last variable in the while loop.
I need it so I can access all of the variables related to each other i.e
giftid and quantity together.
Hope this makes sense, not sure of the right way to progress with this script
thanks......
PHP Code:
include ('connect2.inc');
print "<p> </p><table border='0' cellpadding='1' cellspacing='0' width='90%'>
<tr id='highlight3'><td>Gift</td><td>Quantity</td><td> </td><td>Price</td><td>Subtotal</td></tr>";
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];
$amounted = array($amount);
$ntotal = $price * $amount;
$ntotal = number_format ($ntotal,2);
$subtotal = $subtotal + ($price * $amount);
$subtotal =number_format ($subtotal,2);
print "
<tr id=''><td>$title</td><td>$amount</td><td>x</td><td>£$price</td>
<td>£$ntotal</td></tr>";
}
}
print_r ($_POST['select']);
print_r ($amounted);
// end table
print "
<tr><td colspan='5'> </td></tr>
<tr id='highlight3'><td> </td><td> </td><td> </td>
<td><strong>Total</strong></td>
<td><strong>£$subtotal</strong></td></tr></table>";
|