co.ador Posted March 11, 2010 Share Posted March 11, 2010 I need to place some html code inside the cartexample.php file to list the prices in that script, The prices coming from the Second case type item list in colored green in listofitems.php file, plus some sort of loop integrated inside the existing script in cartexample.php so it can only iterate the prices coming from the Second case type items without alterating the performance of the First case type in the cartexample.php which this script as it is perfectly display the items coming from the First Case Type item list on top of listofitems.php file. listofitems.php file link http://www.nyhungry.com/pmw57/listofitems.php cartexample.php file link http://www.nyhungry.com/pmw57/cartexample.php?action=add_item&id=1&qty=1 Listofitems.php file script below <div class="firstcase">---First Case Type Item list===> <br/> <br/> <span class="style1">Please add your item from the first case type item list to the shopping cart.</span></div> <div id="container"> <div class="wrap"> <?php $query = "SELECT * FROM pantitems"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { while($row3 = mysql_fetch_array($result)) { echo"<div class=\"pantsinfo1\"> <img src=\"images/spacer.gif\" alt=\"spacer\" class=\"spacer2\" /> <h2 class=\"infohead\">". $row3['item'] . "</h2>"; ?> <div class=\"pic\"><img class=\"line\" src="<?php echo $row3['img'] ?> " alt=\"picture\" width=\"100%\" height=\"40%\" /></div> <?php echo "<div class=\"suabe4\">Price:<span class=\"suabe5\">$". $row3['price'] . "</span></div> <!--<h3>Description:</h3> <div id=\"description\"><p> </p></div> --> <p><a href=\"cartexample.php?action=add_item&id=". $row3['id']. "&qty=1\">Add to cart</a></p> </div>"; } } ?> </div> </div> <br/> <br/> <br/> <br/> <div class="secondcase">---Second Case Type Item list===> <br/> <br/> <span class="style1">Please add your Item Lot from the first case type item list to the shopping cart.</span></div> <?php echo'<div id="caterpic2">'; $sql ="SELECT * FROM pantitems, pantslot WHERE pantitems.id= pantslot.product_id AND pantslot.product_id = pantitems.id"; $sth = mysql_query($sql); while($row = mysql_fetch_array($sth)) { $idc = $row['id']; $tree[$idc]['item'] = $row['item']; if($row['variety']) $tree[$idc]['varieties'][] = $row; } foreach($tree as $idc=>$product){ echo'<form action="cartexample.php?action=add_item&id='. $idc . '&qty=1" method="post">'; echo'<div id="namerating"> <p class="name">Name:</p><p class="p">'. $product['item'] . '</p> </div>'; echo'<div class="caterpic">'; echo'<div class="firstiteration">'; foreach($product['varieties'] as $variety){ echo'<div class="'.$variety['classe']. '"> <input style="width:10px; margin-left:9px; " name="dishname" type="hidden" value="'. $product['item'] .'" /> <input style="width:10px; margin-left:9px; " name="price[]" type="checkbox" value="' . $variety['price'].'_'. $variety['variety']. ' " /> <p class="' . $variety['size']. '">'. $variety['variety'] . '</p> <img src="' . $variety['img']. '" width="' . $variety['width']. '" height="'. $variety['height'].'"/> <p class="price">$' . $variety['price']. '</p> <p class="'.$variety['serve'].'">'. $variety['description']. '</p> </div>'; } echo'<input class="addtocart2" name="formSubmit" type="image" value="Submit" src="images/addtocart2.gif" /> </form>'; echo'</div>'; echo'</div>'; } echo"<div class=\"cityclearer3\"></div>"; echo'</div>'; ?> cartexample.php file script below <?php function GetCartId() { // This function will generate an encrypted string and // will set it as a cookie using set_cookie. This will // also be used as the cookieId field in the cart table if(isset($_COOKIE["cartId"])) { return $_COOKIE["cartId"]; } else { // There is no cookie set. We will set the cookie // and return the value of the users session ID session_start(); setcookie("cartId", session_id(), time() + ((3600 * 24) * 30)); return session_id(); } } ?> <?php $id= (int) $_GET['id'];?> <?php switch($_GET["action"]) { case "add_item": { AddItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "update_item": { UpdateItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "remove_item": { RemoveItem($_GET["id"]); ShowCart(); break; } default: { ShowCart(); } } function AddItem($itemId, $qty){ $result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId"); $row = mysql_fetch_row($result); $numRows = $row[0]; if($numRows == 0) { // This item doesn't exist in the users cart, // we will add it with an insert query mysql_query("INSERT INTO cart(cookieId, id, qty) values('" . GetCartId() . "', $itemId, $qty)"); printf ("Inserted records: %d\n", mysql_affected_rows()); } else { // This item already exists in the users cart, // we will update it instead mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId"); } } function UpdateItem($itemId, $qty) { mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId"); //printf ("Updated records: %d\n", mysql_affected_rows()); } function RemoveItem($itemId) { mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId"); } ?> <?php function ShowCart() { $result = mysql_query("SELECT * FROM cart INNER JOIN pantitems ON cart.id = pantitems.id WHERE cart.cookieId = '" . GetCartId() . "' ORDER BY pantitems.item ASC");?> <div id="cart"> <div id="group"> <div id="quantity">Qty</div> <div id="cartpic">Pic</div> <div id="product">Product</div> <div id="cartprice">Price</div> <div id="remove">Remove</div> </div> <?php $totalCost=0; while($row = mysql_fetch_array($result)) { // Increment the total cost of all items $totalCost += ($row["qty"] * $row["price"]); ?> <div id="cart1"> <select name="<?php echo $row["id"]; ?>" onChange="UpdateQty(this)"> <?php for($i = 1; $i <= 30; $i++) { echo "<option "; if($row["qty"] == $i) { echo " SELECTED "; } echo ">" . $i . "</option>"; } ?> </select> </div> <div id="cart2"> <img src="<?php echo $row["img"]; ?>" alt="we" width="60" height="50" /> </div> <div id="cart3"> <p> <?php echo $row["item"]; ?></p></div> <div id="cart4"><p> $<?php echo number_format($row["price"], 2, ".", ","); ?></p></div> <div id="cart5"> <p> <?php printf('<a href="cartexample.php?action=remove_item&id=%d">Remove</a>', $row['id']); ?></p></div> <hr size="1" color="red" > <script language="JavaScript"> function UpdateQty(item) { itemId = item.name; newQty = item.options[item.selectedIndex].text; document.location.href = 'cartexample.php?action=update_item&id='+itemId+'&qty='+newQty; } </script> <!--<div id="videowrapper"> <fieldset class="videofield"> <object width="380" height="265"> <param name="movie" value="videoplayer4.swf"/> <embed src="videos/vaideoplayer4.swf" width="380" height="240"> </embed> </object> </fieldset> </div>--> <?php } ?> <font face="verdana" size="2" color="black" style="clear:right;"> <b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b></font></td> <?php } ?> <div id="shopping"> <a href=<?php echo "listofitems.php?id=". $id .""?>> Keep Shopping</a></div> </div> <br/> <br/> <br/> <br/> <div class="explanation">If you add items from <span class="style1">First Case Type</span> then the cart works ok. The <span class="style1">First Case Type</span> is adding single items to the cart as expected. Now the <span class="style2">Second Case Type</span> has a different display or look in the cart, but right now it is displaying the items as single items not as lots. The <span class="style2">Second Case Type</span> has three categories of a single item as you can see, a small, medium and large lot with different prices, sizes and lots of pieces. I have to say that the name of the item in the <span class="style2">Second Case Type</span> comes from the same table that the single item name on the <span class="style1">First Case Type</span> comes from, the <em>pantitems</em> table. Now the prices, the number of pieces, sizes, and images of the lots in the <span class="style2">Second Case Type</span> comes from a table called <em>pantslot</em>. Which differ from the from <span class="style1">First Case Type</span> where the prices, name and images comes from the same table pantitems. Now the main issue here is to alter the cart where it can receive single items from the <span class="style1">First Case Type</span> as it is doing now and also receive lots of items from the <span class="style2">Second Case Type</span> as it looks in the image below Or Something similar where lots can be added as well as single items <a href="http://www.nyhungry.com/listofitems.php">Here</a></div> <img class="imagesample" src="images/cartexamplefirstcase.jpg" alt="cartexample"> <?php /*?><tr> <td colspan="4"> <font face="verdana" size="1" color="black"> <a href=<?php echo "cart.php?id=".intval($id). '®ister='. $_GET['register']. ""?>>Your Shopping Cart</a></font></td> </tr><?php */?> </tr> </table> </table> I hope I have explained my self enough if not visit this link http://www.nyhungry.com/pmw57/listofitems.php there are complementary explanation to what I already has said here. If not feel free to ask. Thank you. Link to comment https://forums.phpfreaks.com/topic/194959-looking-tomodify-the-cart-script-file-to-hold-items-from-two-list-of-items/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.