Jump to content

3cool4school

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Everything posted by 3cool4school

  1. yup, no errors, and it works in phpmyadmin and deletes all corresponding rows.
  2. Hi all, this is probably the easiest thing and I may have just been staring at the screen for too long but one of my DELETE FROM queries isn't working. I created a cart and in the admin area when an admin deletes the product it is supposed to delete it from the 'Products' table and also all the sizes from the 'Sizes_List' table. Right now it is only being deleted from the Products table and not the Sizes_List table.. here is the snippet.. any help would be greatly appreciated. if (isset($_GET['yesdelete'])) { // remove item from system and delete its picture // delete from database $id_to_delete = $_GET['yesdelete']; $deletefrom_sizes = mysql_query("DELETE FROM Sizes_List WHERE product_id = '$id_to_delete'"); $sql = mysql_query("DELETE FROM Products WHERE product_id='$id_to_delete' LIMIT 1"); // unlink the image from server // Remove The Pic ------------------------------------------- $pictodelete = ("../user/rent/inventory_images/$id_to_delete.jpg"); if (file_exists($pictodelete)) { unlink($pictodelete); } header("location: addproduct.php"); exit(); }
  3. I got it to work! .. Thanks so much!! you are such a help!!!
  4. Thanks for the help! you have been awesome!! .. I have a problem I got the first part to work, and when I add products to the cart they are in the array. but when I implode them and rip them apart in the for loop it doesn't work.. if I echo $ids by itself i get the proper array e.g. 10,12,15 . but the count($ids) says there is 1 number . and in the for loop I echo'd to check and all i got was Piece 0 = 1 . this is what I have before the cart outputs. $ids = implode(',',array_keys($_SESSION['cart_array'])); $query = "SELECT * FROM Products WHERE product_id IN ($ids)"; for($i = 0; $i< count($ids); $i++){ $item_id = $ids[$i]; echo "Piece #$i = $ids[$i] <br />"; } $sql = mysql_query($query); while ($row = mysql_fetch_array($sql)) { $product_brand = $row["product_brand"]; $product_style = $row["product_style"]; $credits = $row["credits"]; $details = $row["details"]; $sql4 = mysql_query("SELECT * FROM Sizes WHERE size_id = '$asizeid'"); while($name3 = mysql_fetch_array($sql4)){$product_size = $name3['size_name'];} }
  5. Thanks so much! .. That makes so much sense and simplifies the code down so much. But would I still need $each_item? and foreach ($_SESSION["cart_array"] as $each_item) ? Thanks!
  6. Throw in the correct image location lbut you have to have your conditions so something along these lines <?php $theimage = ""; if (SERVER UP CONDITION){ $theimage .= "<img src ='green.png' />"; } elseif (SERVER DOWN CONDITION){ $theimage .= "<img src ='red.png' />"; } elseif (SERVER SLOW CONDITION){ $theimage .= "<img src ='orange.png' />"; } ?> then wherever you want to display is (I would use a div so you can control sizing and location etc) <div class ="serverstatus"> <?php echo $theimage; ?> </div> I'm not sure if you needed help with the actual figuring out if the server was down up or slow
  7. by return are you sending the value somewhere, or just trying to display it?
  8. I might be able to help, I'd like to see a sample.
  9. Hello everyone I have coded a php cart for my website. I coded one myself instead of using a big box because it is a membership based sites where users use credits to order not cash. I have a 'Sizes' table with (size_id and size_name) and a 'Sizes_List' table with (size_id and product_id) which stores the size options of each product. It is displayed fine on the product page. Anyhoo. It works great.. there aren't any actual errors in the code but I am having trouble with 3 things.. 1. displaying the product size [i grab it in $_POST and add it to the cart_array) but it doesn't show up. 2. If I add another product, but a different size, to the cart it just changes the quantity of the product but doesn't add a new line. 3. I need to put items on "hold" for a certain amount of time (e.g. if you add a pair of True Religions in size 32 to your cart they are no longer available to anybody for 20 minutes and if you don't checkout they are back in the store). For the purpose of this question I have removed the need to be logged in for 1 product page and the cart. http://www.theskinnyminnie.com/user/rent/product.php?id=4/ <<product http://www.theskinnyminnie.com/user/mybox.php <<cart Here is the code it POST the values to the cart (if user adds to cart) <div id="addproduct"><form id="form1" name="form1" method="post" action="../mybox.php"> <div id ="size">Size: <select name="size"> <?php echo $the_sizes;?> </select></div> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> <input type="submit" name="button" id="button" value="Add to Box" /> </form></div> Here is the code for the cart User adds to cart: <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 1 (if user attempts to add something to the cart from the product page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (!empty($_POST['form1'])) { $pid = $_POST['pid']; $asizeid = $_POST['size']; echo $asizeid; $wasFound = false; $i = 0; // If the cart session variable is not set or cart array is empty if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { // RUN IF THE CART IS EMPTY OR NOT SET $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1, "asize_id" => $asizeid)); } else { // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $pid) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1, "asize_id" => $asizeid))); $wasFound = true; } // close if condition } // close while loop } // close foreach loop if ($wasFound == false) { array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1, "asize_id" => $asizeid)); } } header("location: mybox.php"); exit(); } ?> User empties shopping car <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 2 (if user chooses to empty their shopping cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") { unset($_SESSION["cart_array"]); } ?> <?php adjust item quantity <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 3 (if user chooses to adjust item quantity) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") { // execute some code $item_to_adjust = $_POST['item_to_adjust']; $quantity = $_POST['quantity']; $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers if ($quantity >= 100) { $quantity = 99; } if ($quantity < 1) { $quantity = 1; } if ($quantity == "") { $quantity = 1; } $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $item_to_adjust) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity, "asize_id" => $asizeid))); } // close if condition } // close while loop } // close foreach loop } ?> remove item <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 4 (if user wants to remove an item from cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") { // Access the array and run code to remove that array index $key_to_remove = $_POST['index_to_remove']; if (count($_SESSION["cart_array"]) <= 1) { unset($_SESSION["cart_array"]); } else { unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } ?> View Cart - Ignore $orderSummary it is for the checkout process .. <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 5 (render the cart for the user to view on the page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $cartOutput = ""; $itemtotal = ""; $cartTotal = ""; $orderTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $itemtotal = "0"; $cartOutput = "<h2 align='center'>Your shopping cart is empty</h2><br />"; } else { $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM Products WHERE product_id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_brand = $row["product_brand"]; $product_style = $row["product_style"]; $credits = $row["credits"]; $details = $row["details"]; } $sql4 = mysql_query("SELECT * FROM Sizes WHERE size_id = '$asize_id'"); while($name3 = mysql_fetch_array($sql4)){$product_size = $name3['size_name'];} $creditstotal = $credits * $each_item['quantity']; $cartTotal = $creditstotal + $cartTotal; $orderTotal = $creditstotal + $orderTotal; $itemtotal += $each_item['quantity']; $orderItem_qty = $each_item["quantity"]; $orderItem_total += $each_item["quantity"]; $orderSummary .= "<tr>"; $orderSummary .= "<td>"; $orderSummary .= "<div class = 'an_order_item'>"; $orderSummary .= "<img class ='an_order_img' src = 'inventory_images/".$item_id.".jpg' />"; $orderSummary .= "<div class = 'an_order_box'>"; $orderSummary .= "<div class = 'an_order_title'>"; $orderSummary .= "<h1>".$product_brand." - <font color='black'>".$product_style. "</font></h1>"; $orderSummary .= "</div>"; $orderSummary .= "<div class = 'an_order_size'>"; $orderSummary .= "<h1>Size - ".$product_size."</h1>"; $orderSummary .= "</div>"; $orderSummary .= "<div class = 'an_ordercalc'>"; $orderSummary .= "<h1>".$orderItem_qty." x ".$credits."pts = ".$creditstotal."pts</h1>"; $orderSummary .= "</div>"; $orderSummary .= "</div>"; $orderSummary .= "</div>"; $orderSummary .= "</div>"; $orderSummary .= "</div>"; $orderSummary .= "</td>"; $orderSummary .= "</tr>"; $orderSummary2 .= "<tr>"; $orderSummary2 .= "<td>"; $orderSummary2 .= "<div class = 'an_order_item'>"; $orderSummary2 .= "<img class ='an_order_img' src = 'rent/inventory_images/".$item_id.".jpg' />"; $orderSummary2 .= "<div class = 'an_order_box'>"; $orderSummary2 .= "<div class = 'an_order_title'>"; $orderSummary2 .= "<h1>".$product_brand."</h1>"; $orderSummary2 .= "<h1><font color='black'>".$product_style. "</font></h1>"; $orderSummary2 .= "</div>"; $orderSummary2 .= "</div>"; $orderSummary2 .= "</div>"; $orderSummary2 .= "</div>"; $orderSummary2 .= "</div>"; $orderSummary2 .= "</td>"; $orderSummary2 .= "</tr>"; $x = $i + 1; $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= $sizeid; $cartOutput .= '<td class="img"><a href="rent/product.php?id=' . $item_id . '"><img src="rent/inventory_images/' . $item_id . '.jpg" alt="' . $product_brand. '" height="121px" border="1" /></a><br /></td>'; $cartOutput .= '<td class="desc"> <strong><a href="rent/product.php?id=' . $item_id . '">' . $product_brand."-".$product_style . '</a></strong><ul class="attributes"><li>'. $details .'</li></ul><p class="size">Size - '.$product_size.'</p></td>'; $cartOutput .= '<td class="price">' . $credits .' <font id="pts">PTS</font></td>'; $cartOutput .= '<td class="qty"><form action="mybox.php" method="post"> <input name="quantity" type="number" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input class="change" name="adjustBtn' . $item_id . '" type="submit" value="Update" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form> <form action="mybox.php" method="post"><input class="delete" name="deleteBtn' . $item_id . '" type="submit" value="Remove" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form> </td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td class="total">' . $creditstotal .'</td>'; $cartOutput .= '</tr>'; $i++; } setlocale(LC_MONETARY, "en_US"); //$cartTotal = $cartTotal.''; $cartTotal = '<tr><td colspan="4">Total</td><td class="total cart-total-price">' . $cartTotal .'</td></tr>'; // Finish the Paypal Checkout Btn } ?>
  10. You were right!!.. Also i had product_index and products_index used interchangably.. thanks so much everyone!
  11. Ok i got the code to work with the tables : http://www.theskinnyminnie.com/user/rent/ the only issue now is tha after ther first product it doesn't recognize the rest.. This is the code I implemented with mine. <?php // Run a select query to get my letest 6 items // Connect to the MySQL database $min = 1; $max = 4; $sql = mysql_query("SELECT * FROM Products ORDER BY date_added DESC LIMIT $min,$max"); $number_of_products = mysql_num_rows($sql); // count the output amount if ($number_of_products > 0) { while($product = mysql_fetch_array($sql)){ $products_name[] = $product["product_name"]; $products_id[] = $product["product_id"]; $products_price[] = $product["credits"]; $products_added[] = strftime("%b %d, %Y", strtotime($product["date_added"])); $number_of_rows = $number_of_products/5; $product_index = 0; $the_table = '<table>'; for($row=0; $row < $number_of_rows; $row++){ $the_table .='<tr>'; for($col = 0; $col < 5; $col++){ if($products_index < count($products_name)){ $the_table .= '<td><a href="product.php?id=' .$products_id[$products_index]. '"><img src="inventory_images/' .$products_id[$products_index]. '.jpg" alt="' .$products_name[$products_index]. '" width="77" height="102" border="1" /></a><br /><a href="product.php?id=' .$products_id[$products_index]. '">' .$products_name[$products_index]. '</a><br />' .$products_price[$products_index]. 'pts</td>'; $products_index++; }else{ $the_table .='<td><img src="../../images/noprofile.jpg" width="77" height="102" border="1"> <br />NO PRODUCT <br />NO PRICE</td>'; } } $the_table .='</tr>'; } $the_table .='</table>'; } }else { $the_table = "We have no products listed in our store yet"; } mysql_close(); ?> But I'm pretty sure the problem lies within here for($row=0; $row < $number_of_rows; $row++){ $the_table .='<tr>'; for($col = 0; $col < 5; $col++){ if($products_index < count($products_name)){ $the_table .= '<td><a href="product.php?id=' .$products_id[$products_index]. '"><img src="inventory_images/' .$products_id[$products_index]. '.jpg" alt="' .$products_name[$products_index]. '" width="77" height="102" border="1" /></a><br /><a href="product.php?id=' .$products_id[$products_index]. '">' .$products_name[$products_index]. '</a><br />' .$products_price[$products_index]. 'pts</td>'; $products_index++; }else{ $the_table .='<td><img src="../../images/noprofile.jpg" width="77" height="102" border="1"> <br />NO PRODUCT <br />NO PRICE</td>'; } Any suggestions?
  12. Thank you everyone! .. I'm going to try to implement it now. Should all of it go inside the while array?
  13. Oh wow! Thanks so much for your quick reply!. I want it sorted Row by Row.. Also if you could point me in the right direction to acheive pagination that would be great. I want to code it myself just need to know where to start. Would it be a while for the pages and then a counter as to where I stopped then display products after that counter on the next page? Nevermind! I just use LIMIT for pagination.. got it lol .. but still need help with the Row by Row!
  14. Hello I have a custom php cart working great, with product pages and shopping cart and checkout using points rather than money. My problem is that I cannot get the actual product pages to display in colums (I want 5 items per colum and 8 rows per page). Instead the whole thing is displayed as a row. Here is the page that the products are shown on: http://www.theskinnyminnie.com/user/rent/ (I have removed the need to be signed on) Here is the code I am using: <?php // Run a select query to get myproducts $dynamic List =""; $sql = mysql_query("SELECT * FROM Products ORDERY BY date_added DESC"); $productCount = mysql_num_rows($sql)){ if(productCount > 0){ while($row = mysql_fetch_array($sql)){ $id = $row["product_id"]; $product_name = $row["product_name"]; $price = $row["credits"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<tr> <td><a href="product.php?id=' . $id . '"><img src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td></tr> <tr> <td><a href="product.php?id=' . $id . '">' . $product_name . '</a></td> </tr> <tr> <td>' . $price . 'pts</td> </tr> <tr> <td> </td> </tr>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> and then i echo dynamicList
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.