stallprophet Posted July 20, 2007 Share Posted July 20, 2007 I am a little burned out and need a little help on this. The basic summary: I have a shopping cart script sending info to a processor. I need to send the qty's and item name's in some sort of string via a single variable to the process form. i.e. (3) Hipster Turnips, (6) Butter Milk Baby Brains, (2) Super Freaks Here is the script: <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { include 'db_connect.php'; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } echo "<form action=\"cart.php?action=update\" method=\"post\" id=\"cart\">"; foreach ($contents as $id=>$qty) { $conn2 = db_connect(); if ($conn2) { $query2 = "SELECT * FROM itmes WHERE id = $id"; $result2 = mysql_query($query2,$conn2); ///echo $result; } else { exit("<font color=\"#000000\">There is an error connecting to database, please cont act an administrator."); } ///echo $result; $id2=mysql_result($result2,$i2,"id"); $img=mysql_result($result2,$i2,"img"); $price=mysql_result($result2,$i2,"price"); $desc2=mysql_result($result2,$i2,"description"); $desc = urldecode($desc2); $item_name=mysql_result($result2,$i2,"name"); $name2 = urldecode($item_name); ?> <div style="padding: 5px; background-color: #fff;"> <img src="<?php echo $img;?>" width="18%" style="padding: 5px; margin-right: 5px; border: 1px solid #663398; background-color: #FFF;" align="left" /><h2 style="padding:0; margin:0;"><?php echo $name2;?></h2> <a href="cart.php?action=delete&id=<?php echo $id;?>" class="r">Remove</a> <input type="text" name="qty<?php echo $id;?>" value="<?php echo $qty;?>" size="3" maxlength="3" /> <? echo '$'.($price * $qty); $total += $price * $qty; ?> <p><?php echo $desc;?><p></div> <? } echo '<div style=""><p><h2>Grand total: <strong>$'.$total. '</strong></h2></p>'; echo '<p><input type="submit" value="Update cart"/></form>'; echo '<form action="phpauthnet_aim/orderform.php"><input type="hidden" name="cost" value='.$total.'>If everything is good: <input type="submit" value="proceed to checkout"/></form></p></div>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Any help would be wonderfully received and a whole bowl of strawberry karma will be waiting for you... Quote Link to comment https://forums.phpfreaks.com/topic/60906-mysql-result-into-array/ Share on other sites More sharing options...
stallprophet Posted July 20, 2007 Author Share Posted July 20, 2007 I assume some array is in order. Just cannot wrap my brain around it. Quote Link to comment https://forums.phpfreaks.com/topic/60906-mysql-result-into-array/#findComment-303083 Share on other sites More sharing options...
samtay Posted July 20, 2007 Share Posted July 20, 2007 I What functions is it in? Quote Link to comment https://forums.phpfreaks.com/topic/60906-mysql-result-into-array/#findComment-303086 Share on other sites More sharing options...
sKunKbad Posted July 20, 2007 Share Posted July 20, 2007 mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/60906-mysql-result-into-array/#findComment-303088 Share on other sites More sharing options...
stallprophet Posted July 20, 2007 Author Share Posted July 20, 2007 The main info is generated in the showCart() function. The problem is the result from the query only gives me the name. The qty I am getting from an array created from the $contents = array() and am having troubles with putting the two together... again my brain is rapidly deteriorating. Does this help? Quote Link to comment https://forums.phpfreaks.com/topic/60906-mysql-result-into-array/#findComment-303092 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.