s_ainley87 Posted April 24, 2008 Share Posted April 24, 2008 Hello, I am currently creating an online with good intergration for checkoing out, I have assigned variables that are placed into to hidden fields and sent to google, the problem arises when the loop kicks in, as it resets the variables and reassignes them to the old value rather than the next values, // Print each item. $total = 0; // Total cost of the order. while ($row = mysql_fetch_array ($result)) { $count = $count+1; $subtotal = $_SESSION['cart'][$row['product_id']]['quantity'] * $_SESSION['cart'][$row['product_id']]['price']; $total += $subtotal; //setting table variables $catname = $row['category_name']; $prodname = $row['product_name']; $price = $_SESSION['cart'][$row['product_id']]['price']; $quantity = $_SESSION['cart'][$row['product_id']]['quantity']; // Print the row. echo " <tr> <td align=\"left\" bgcolor=\"#cccccc\">{$row['category_name']}</td> <td align=\"left\" bgcolor=\"#cccccc\">{$row['product_name']}</td> <td align=\"right\" bgcolor=\"#cccccc\">£{$_SESSION['cart'][$row['product_id']]['price']}</td> <td align=\"center\" bgcolor=\"#cccccc\"><input type=\"text\" size=\"3\" name=\"qty[{$row['product_id']}]\" value=\"{$_SESSION['cart'][$row['product_id']]['quantity']}\" /></td> <td align=\"right\" bgcolor=\"#cccccc\">£" . number_format ($subtotal, 2) . "</td> </tr>\n"; } // End of the WHILE loop. mysql_close($dbc); // Close the database connection. // close the table, and the form. echo ' <tr> <td colspan="4" align="right"><b>Total:<b></td> <td align="right">£' . number_format ($total, 2) . '</td> </tr> </table><div align="center"><input type="submit" name="submit" value="Update My Cart" /> <input type="hidden" name="submitted" value="TRUE" /> </form><br /><br />'; ?> <?php } else { echo '<p>Your cart is currently empty.</p>'; } ?> <?php echo"<form id=\"googlecheckout\" method=\"POST\" action = \"https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/453070710704027\" accept-charset=\"utf-8\">"; while ($count > 0) { echo"<input type=\"hidden\" name=\"item_description_$count\" value=\"$catname\" /> <input type=\"hidden\" name=\"item_name_$count\" value=\"$prodname\" /> <input type=\"hidden\" name=\"item_price_$count\" value=\"$price\" /> <input type=\"hidden\" name=\"item_quantity_$count\" value=\"$quantity\"/> <input type=\"hidden\" name=\"item_currency_$count\" value=\"GBP\"/>"; $count --; } echo "<input type=\"image\" name=\"Google Checkout\" alt=\"Fast checkout through Google\" src=\"http://checkout.google.com/buttons/checkout.gif?merchant_id=453070710704027&w=180&h=46&style=white&variant=text&loc=en_US\" height=\"46\" width=\"180\"/> </form>"; echo $row; ?> A live version can be here http://www.jetexed.org.uk/store forgive me for the basd coding I am self taught and still learning. Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/ Share on other sites More sharing options...
s_ainley87 Posted April 24, 2008 Author Share Posted April 24, 2008 Bump..... Please some1 help me :-( Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-526610 Share on other sites More sharing options...
947740 Posted April 24, 2008 Share Posted April 24, 2008 Try making the variables arrays, appending [$count] to the end. This will prevent overwriting. You will have to adjust your code whenever you access the data, however. Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-526643 Share on other sites More sharing options...
s_ainley87 Posted April 24, 2008 Author Share Posted April 24, 2008 Sorry I am really quite stupid when it comes to PHP, could you explain alittle more please? Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-526658 Share on other sites More sharing options...
947740 Posted April 24, 2008 Share Posted April 24, 2008 I have a quick question. What is your original $count value? I am not seeing a declaration for that value. Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-526664 Share on other sites More sharing options...
s_ainley87 Posted April 24, 2008 Author Share Posted April 24, 2008 the original value is $count = $count+1; Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-526670 Share on other sites More sharing options...
947740 Posted April 25, 2008 Share Posted April 25, 2008 Don't you have to have something to add 1 to though? Or is it just a theoretical value? Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-527054 Share on other sites More sharing options...
s_ainley87 Posted April 25, 2008 Author Share Posted April 25, 2008 I dont know what you mean sorry. Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-527063 Share on other sites More sharing options...
947740 Posted April 25, 2008 Share Posted April 25, 2008 My point is that there is not a value to $count, but you are adding 1 to it. I think you have to make it soemthing like $count = 0, and then $count = $count+1. I am having a hard time explaining this...maybe I am the one that is confused... Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-527070 Share on other sites More sharing options...
Yesideez Posted April 25, 2008 Share Posted April 25, 2008 Just for info, $count=$count+1 can be replaced with $count++ Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-527071 Share on other sites More sharing options...
s_ainley87 Posted April 25, 2008 Author Share Posted April 25, 2008 Yeah thanks not got to tidying yet, what i am looking to do is ieterate through an array and pull the deatils from it, and add the deatils to hidden fields of a form...I need to iterate until all products in the session have been looked at. Quote Link to comment https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/#findComment-527078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.