Accolade Posted November 7, 2012 Share Posted November 7, 2012 (edited) I am adding items to my cart.php using an add increment case statement. case "add": if (isset($_SESSION['cart'][$comic_id])) { $_SESSION['cart'][$comic_id]++; } else { $_SESSION['cart'][$comic_id] = 1;} My items are presented into an HTML table in the cart.php. I just want to then re-call specific variables from the array in the checkout.php so the customer can confirm the order total along with their personal details. I can only seem to carry the last row over using SESSION variable. e.g. $_SESSION['totalnameqty']=$name . " " . $qty . " " . $total; I want to call all of the rows that exist in the cart.php HTML table. cart.php: if (isset($_SESSION['cart'][$comic_id])){ echo "<table border=\"0\" padding=\"10\" width=\"80%\">"; echo "<td colspan=\"1\" align=\"left\"><a href=\"title.php\">Continue Shopping</a></div>"; echo "<td colspan=\"6\" align=\"right\"><a href=\"$_SERVER[php_SELF]?action=empty\" onclick=\"return confirm('Crystal Fusion: Are you sure you wish to empty your cart?');\">Empty Cart</a></td>"; echo "<tr height=\"20px\">"; echo "<tr height=\"20px\">"; echo "<td align=center>Image</td><td align=center>Title</td><td align=center>Description</td><td colspan=3 align=center>Copies (+/-)</td><td align=center>Price</td>"; echo "<tr height=\"20px\">"; foreach($_SESSION['cart'] as $comic_id => $qty) { $sql = sprintf("SELECT title, description, cost, image_thumbnail FROM comic WHERE comic_id = %d;",$comic_id); $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { list($name, $description, $price, $image_thumbnail) = mysql_fetch_row($result); $cost = $price * $qty; $total = $total + $cost; $cost = number_format($cost,2); $total = number_format($total,2); $description = substr($description, 0, 250); echo "<br><tr>"; echo "<td width=\"10px\" align=\"center\"><img height=100 align=center src=\"$image_thumbnail\">"; echo "<td align=\"center\">$name</td>"; echo "<td width=\"40%\" align=\"center\">$description...<a href=comic_dyn.php?comic_id=$comic_id>More Info</td>"; echo "<td width=\"30px\" align=\"center\"><a href=\"$_SERVER[php_SELF]?action=add&comic_id=$comic_id\">+<br></a><td align=\"center\">$qty <td width=\"20px\" align=\"center\"><a href=\"$_SERVER[php_SELF]?action=remove&comic_id=$comic_id\">-</a></td>"; echo "<td align=\"right\">$$cost</td>"; echo "</tr>"; } } echo "<br><tr><tr height=100px>"; echo "<td><td><td colspan=\"4\" align=\"right\">Total:</td>"; echo "<td width=\"60px\" align=\"right\">$$total</td>"; echo "<tr><td colspan=\"7\" align=\"right\"><a href=\"checkout_html.php\">Proceed to Checkout</a>"; echo "<tr height=\"50px\">"; echo "</table>"; }else{ echo "Your cart is currently empty."; echo "<br><br><td colspan=\"1\" align=\"left\"><a href=\"title.php\">Continue Shopping</a></div>"; } Edited November 7, 2012 by Accolade Quote Link to comment https://forums.phpfreaks.com/topic/270415-problem-with-session/ Share on other sites More sharing options...
MDCode Posted November 7, 2012 Share Posted November 7, 2012 Ok. Do you have a question? Quote Link to comment https://forums.phpfreaks.com/topic/270415-problem-with-session/#findComment-1390867 Share on other sites More sharing options...
Accolade Posted November 7, 2012 Author Share Posted November 7, 2012 Im not sure how to call all the rows from the HTML table / array on the next page using SESSION? When I use: $_SESSION['totalnameqty']=$name . " " . $qty . " " . $total; ...I only get the last entry entered into the array returned, rather than all of them. Quote Link to comment https://forums.phpfreaks.com/topic/270415-problem-with-session/#findComment-1390952 Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2012 Share Posted November 8, 2012 You would make it an array - $_SESSION['totalnameqty'][]=$name . " " . $qty . " " . $total; Quote Link to comment https://forums.phpfreaks.com/topic/270415-problem-with-session/#findComment-1390984 Share on other sites More sharing options...
Accolade Posted November 8, 2012 Author Share Posted November 8, 2012 Notice: Array to string conversion Quote Link to comment https://forums.phpfreaks.com/topic/270415-problem-with-session/#findComment-1391065 Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2012 Share Posted November 8, 2012 Without the code that produces that error, best guess is you are trying to use the array as a string, rather than to iterate over the array to access each element. Quote Link to comment https://forums.phpfreaks.com/topic/270415-problem-with-session/#findComment-1391066 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.