PHP - Creating A Product Gallery
Hello. I am rolling my first-ever e-commerce site, and could use some help on designing a product gallery. My site will be selling books and guides, and similar to what you might see on Amazon or Barnes & Noble, I want to create a product gallery which displays all products for a given category. For simplicity, let's say that I am only selling paper books, and that is what I want to display - so for the purposes of this conversation, no need to filter on product type. When a user clicks on the product catalog, I was thinking of simply displaying all products (e.g. eBooks) in gallery containing thumbnails in a grid arrangement. The user would click on the thumbnail - which would be the cover of the book - and then be taken to a product page which would have all of the details, including: a larger thumbnail of the book, book title, description, price, author, etc. I suppose I could have a test title and description below each thumbnail? Anyways, I am a little uncertain of how all of this would work from a technical standpoint?! I guess I was thinking that each thumbnail would have a link behind it, which would then load my "product_details.php" page AND pass along something like a "ProductID" in the URL, so that my product_details.php" script could query my database and pull up the book's details. How does that sound? I look forward to hearing what you PHP gurus have to say!! 🙂
Similar TutorialsHi, I have a database of products but I am finding it diffult to understand how to categorise each product and build a site for it. Can I do something like this: $category = ( $gamesconsoles = ( playstation, xbox, wii ) $personalhygiene = ( electric toothbrush, electric razor, electric shaver) ) So I have PHP code which identifies a 'Playstation' as a $gamesconsoles. It then enters a 'gamesconsoles' tag into the database in a category field. I then I have link on my site which looks something like this on the homepage: productrange.php?category="gamesconsoles" class="menulink">Games Consoles</a> I then link to a productrange.php page which has in it: $category = category; if (isset($_GET['category'])) { $id = $_GET['category']; } I then echo all the producys from the database which come under the category of 'gamesconsoles'. Or am I completely mad and it should be done differently. If so please advise. Hello, I've created a page search to return results from my database inventory. On top of these results I would like to display a seperate list of five products not included in the search results but share the same sub_category_b (a column in my SQL table). Posted below is my primary query of the database. If anyone can help me out with this it would be appreciated. Code: [Select] $colname_product = "-1"; if (isset($_GET['title'])) { $colname_product = $_GET['title']; } mysql_select_db($database_inventory, $inventory); $query_product = sprintf("SELECT * FROM inventory WHERE item_name LIKE %s OR item_desc LIKE %s ", GetSQLValueString("%" . $colname_product . "%", "text"),GetSQLValueString("%" . $colname_product . "%", "text")); $product = mysql_query($query_product, $inventory) or die(mysql_error()); $row_product = mysql_fetch_assoc($product); I've fooled around with this one for some time and haven't come up with a clear cut answer. Thank you in advance! Hello, I'm very new to working with images and headers, i've never done it at all even. But i've been trying to make a gallery its got about 150 photos in it. And i know there are much better ways than me resizeing and saving 150 thumbs. So ive tried to research and implement a code to make this so i can recall the original images url from a database and this will be the end viewable picture. And use php to create a thumbnail from the original, and then make that a link so it moves onto a lightbox viewer. this is the code i've got so far, i'm having problems with the headers. I know that they must be put first but when i move the header to the start of file it still errors. I'd really appreciate any help that people would be willing to give <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-type" /> <title></title> <link rel="alternate" type="application/rss+xml" title="" href="http://www.loukafinefinish.com/rss.xml" /> <link rel="stylesheet" type="text/css" href="css/portfolio.css" /> <link rel="stylesheet" type="text/css" href="css/portfolio_image.css" /> <script type="text/javascript" src="js/cufon-yui.js"></script> <script type="text/javascript" src="js/arial.js"></script> <script type="text/javascript" src="js/cuf_run.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/portfolio.js"></script> <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script> <link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" media="screen" /> <script type="text/javascript"> $(function() { $('.thumb a').lightBox(); }); </script> <style type="text/css"> /* Reset CSS */ html, body, h1, h2, h3, h4, h5, h6, p, ol, ul, li, pre, code, address, variable, form, fieldset, blockquote { padding: 0; margin: 0; font-size: 100%; font-weight: normal; } table { border-collapse: collapse; border-spacing: 0; } td, th, caption { font-weight: normal; text-align: left; } img, fieldset { border: 0; } ol { padding-left: 1.4em; list-style: decimal; } ul { padding-left: 1.4em; list-style:square; } q:before, q:after { content:''; } /* End of CSS Reset*/ </style> </head> <body> <div id="content-wrapper"> <div id="header"> <h1><a id="logo" href="index.html"><span>Carpentery</span></a></h1> </div> <div id="navigation"> <div class="menu_nav"> <ul> <li><a href="index.html">Home</a></li> <li><a href="services.htm</ul> <--header above etc--> <?php echo '<div class="container"> <ul class="thumb">'; require_once('include/connect.php'); $display = 5; // Number of results if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Determine number of pages $pages = $_GET['p']; } else { // Need to determine $q = "SELECT COUNT(id) FROM portfolio"; $r = @mysqli_query($dbc, $q); $row = @mysqli_fetch_array($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if($records > $display) { // More than 1 page $pages = ceil($records/$display); } else { $pages = 1; } } // End IF if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Query $q = "SELECT imageUrl FROM portfolio ORDER BY id LIMIT $start, $display"; $r = @mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $filename[] = $row['imageUrl']; foreach ($filename as $url) { // The file $filename = $url; // Set a maximum height and width $width = 100; $height = 100; header('Content-type: image/jpeg'); // Header is here for my example, but i have tried // placing it at the top of my page // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); echo '<li><a href=' . $row['imageUrl'] . '>' . imagejpeg($image_p, null, 100) . ' </a>'; } // End of FOR } // End while echo '</ul>'; // End of list of images mysqli_free_result($r); mysqli_close($dbc); if ($pages > 1) { // Make page links echo '<br /><p class="pagination">'; $current_page = ($start/$display) + 1; // What page script is on if($current_page != 1) { // Make previous button echo '<a href="portfolio.php?s=' . ($start - $display) . '&p=' . '">Previous</a> '; } // Make all the pages numbered for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="portfolio.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // END of FOR loop // If no last page, make net button if ($current_page != $pages) { echo '<a href="portfolio.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; } echo '</p>'; } // End page links ?> <!--Footer etc--> </html> This is my overall page, but as the page had some html involved i thought it best to post some of it. I'm not convinced at all that my method for iterating through the database for the image urls allows me to then iterate this into the $filename for the image resize. If any one could help i'd appreciate it Thank you Hi there, I'm trying to get the full Product Name in the <title> of each of the product pages - I can't seem to figure out what to put in the product_info.php... I've tried a few different options but I'm not great with php Here's what I have currently but it creates errors... <script language="javascript"><!-- document.write('<title><?php echo TITLE; ?> : <?php echo $product_info['products_name']; ?> </title>'); //--></script> Hope someone can help - thanks so much! I cant get my head around this. I m trying to add product attributes into this script. I have products tables and product_extras product.id and product_extras.id are same. How can I add this to cart. Is there any easy way to do this. Any help would be much appreciated! Quote cart.php Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>products</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <p><a href="index.php">Back to products...</a></p> </div> </body> </html> Quote functions.php Code: [Select] <?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() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> hi, baiscally i have a products that go into the products mysql and get called by php but with each product there are different options, e.g. mens jumper - comes in sizes m,l,xl,xxl mens jeans might only come in s, m, l shoes are in 6,7,8,9,10,11 my question is how do i make a drop down list different for each product, when there all in the same db, if some one can reccomend a tutorial or a concept, i would really appreciate it thank you Hello. I just created a product gallery containing thumbnails of items that I will be selling. When a user click on on of the thumbnails, I want a product details page to appear with more details about the chosen product Could use some feedback if I am going about things the right way... Step 1: User goes to my gallery located he www.mysite.com/store/product-gallery.php Step 2: System displays a page of thumbnails representing items that I am selling. Step 3: User click on a given thumbnail which is a hyperlink to: www.mysite.com/store/products/4571 Step 4: System rewrites the URL as such: www.mysite.com/store/products.php?sku=4571 Step 5: System queries MySQL and retrieves record for sku 4571 Step 6: System displays product details for the chosen item in Step 3 which is sku 4571
How does that sound?
I am wanting to do something similar to this: http://www.dimarzio.com/pickup-picker My question involves the concept rather than any specific code on how to execute this. For example, we are selling violins and we want the user to input info about their playing style, and give them the three best violins based on their entry. This is the data I've been given: Level: Beginner Intermediate Advanced Soil, Kreisler, Gibson Soil, Kreisler, Ysaye, Cremonese, Gibson Cannon, Soil, Ysaye, K.Joseph, Keifetz Bowing Style: Soft Medium Hard Soil, Medici, Kreisler Soil, Medici, K.Joseph, Ysaye Cannon, Kreisler, Soil, Heifetz Musical Style Classical Fiddle Rock Ysaye, Soil, Provigny Medici, Ysaye, K.Joseph Kreisler, Diable, Vieuxtemps Desired Tone: Bright Balanced Dark Soil, Medici, Provigny Kreisler, Soil, Ysaye Cannon, Diable, Plowden So if the user inputs Expert, Hard, Rock, and Dark I will data sets of violins consisting of: Cannon, Soil, Ysaye, K.Joseph, Heifetz // Cannon, Kreisler, Soil, Heifetz // Kreisler, Diable, Vieuxtemps // Cannon, Diable, Plowden Out of those I need to output the user the three best choices for them. Cannon is listed in 3 out of the 4, so that has to be #1. Now there are three more violins that match two of the criteria. The Soil, Kriesler and Diable. In order to drill that down to two choices, I would think the questions would have to be ranked according to importance. For instance Tone is most important, followed by bowing style, musical genre, and skill level. Based on that ranking, the program should choose the Diable and Kreisler. I am not entirely sure how to approach this. Since this data will not change frequently, should this even get the database involved? Should the info just be stored in a multi-dimensional array? Once the data is in an array, whether from the DB or not, how should I go about programming the logic to examine the arrays in order of importance and grab the violins that are most relevant? Any help is much appreciated! I figured this was going to be easy, until I actually started thinking about it! I have made a custom post type for products, and am using a custom taxonomy for the product categories. The thing that I am wondering about is that sometimes a product category is a parent, and sometimes a child, but sometimes both. For instance, if you have a top level category named shoes, then you might have a sub category named Nike. However, Nike also has shirts, so you could say that shoes and shirts were both subcategories of Nike. Do you know what I'm saying? It's like there is no real parent to child relationship, but they are both parents and both children of each other. How do you handle this type of situation?
I got a problem guys, when I wanna add a product to my cart it wont add the product to my cart. I get send to my cart and than there is no product. http://www.esolarcharger.com/new Product.php Code: [Select] <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Check to see the URL variable is set and that it exists in the database if (isset($_GET['id'])) { // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $id = preg_replace('#[^0-9]#i', '', $_GET['id']); // Use this var to check to see if this ID exists, if yes then get the product // details, if no then exit this script and give message why $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { // get all the product details while($row = mysql_fetch_array($sql)){ $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "That item does not exist."; exit(); } } else { echo "Data to render this page is missing."; exit(); } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $product_name; ?></title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="15"> <tr> <td width="19%" valign="top"><img src="inventory_images/<?php echo $id; ?>.jpg" width="142" height="188" alt="<?php echo $product_name; ?>" /><br /> <a href="inventory_images/<?php echo $id; ?>.jpg">View Full Size Image</a></td> <td width="81%" valign="top"><h3><?php echo $product_name; ?></h3> <p><?php echo "$".$price; ?><br /> <br /> <?php echo $details; ?> <br /> </p> <form id="form1" name="form1" method="post" action="cart.php"> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> <input type="submit" name="button" id="button" value="Add to Shopping Cart" /> </form> </td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html> Cart.php Code: [Select] <?php ob_start(); // Start session first thing in script // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 1 (if user attempts to add something to the cart from the product page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['pid'])) { $pid = $_POST['pid']; $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)); } 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))); $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)); } } header("location: cart.php"); exit(); } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 2 (if user chooses to empty their shopping cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") { unset($_SESSION["cart_array"]); } ?> <?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))); } // close if condition } // close while loop } // close foreach loop } ?> <?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"]); } } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 5 (render the cart for the user to view on the page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>"; } else { // Start PayPal Checkout Button $pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="support@tranceprofile.com">'; // Start the For Each loop $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; } $pricetotal = $price * $each_item['quantity']; $cartTotal = $pricetotal + $cartTotal; setlocale(LC_MONETARY, "en_US"); $pricetotal = money_format("%10.2n", $pricetotal); // Dynamic Checkout Btn Assembly $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> '; // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>'; $cartOutput .= '<td>' . $details . '</td>'; $cartOutput .= '<td>$' . $price . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input name="adjustBtn' . $item_id . '" type="submit" value="change" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>' . $pricetotal . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartOutput .= '</tr>'; $i++; } setlocale(LC_MONETARY, "en_US"); $cartTotal = money_format("%10.2n", $cartTotal); $cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Cart Total : ".$cartTotal." USD</div>"; // Finish the Paypal Checkout Btn $pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '"> <input type="hidden" name="notify_url" value="https://www.tranceprofile.com/storescripts/my_ipn.php"> <input type="hidden" name="return" value="https://www.tranceprofile.com/checkout_complete.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cbt" value="Return to The Store"> <input type="hidden" name="cancel_return" value="https://www.tranceprofile.com/paypal_cancel.php"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency_code" value="USD"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!"> </form>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Your Cart</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <div style="margin:24px; text-align:left;"> <br /> <table width="100%" border="1" cellspacing="0" cellpadding="6"> <tr> <td width="18%" bgcolor="#C5DFFA"><strong>Product</strong></td> <td width="45%" bgcolor="#C5DFFA"><strong>Product Description</strong></td> <td width="10%" bgcolor="#C5DFFA"><strong>Unit Price</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Quantity</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Total</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> <!-- <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> --> </table> <?php echo $cartTotal; ?> <br /> <br /> <?php //echo $pp_checkout_btn; ?> <br /> <br /> <a href="cart.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a> </div> <br /> </div> <?php include_once("template_footer.php");?> </div> </body> </html> i have shopping cart i need to make the related product section in which i can show the related product when user view the product details. do i need to create any table for it ? please guide me about it. thanks Hello all! I am new to the forums and this is my first post. I've tried to search for an answer but have come up empty handed so I thought I'd just ask outright. I am building a website for a local car dealership and they want to have a "Vehicles" page where it shows a list of all the vehicles in inventory and the consumer can sort the inventory by Make, Model, Year, Color, and/or Price. I'm working with php and MySQL and I am a newbie coder trying to learn on my own. I know how to sort querys but I am completely lost when it comes to sorting with dynamic/multiple variable chosen by the user. Please help. I know my code sucks but any advise will be SUPER helpful. Code: [Select] <?php include "storescripts/connect_to_mysql.php"; if(isset($_POST['Year'])){ $where = "WHERE"; if(isset($_POST['Color'])) { $and = "AND"; } else { $and = ""; } if(isset($_POST['Model'])) { $and = "AND"; } else { $and = ""; } $yearArr = "'" . implode("','", $_POST['Year']) . "'"; $yearSort = "Year IN($yearArr) $and"; if(isset($_POST['Color'])){ $colorArr = "'" . implode("','", $_POST['Color']) . "'"; $colorSort = "Color IN($colorArr)"; } else { $colorArr = ""; $colorSort = ""; } if(isset($_POST['Model'])){ $modelArr = "'" . implode("','", $_POST['Model']) . "'"; $modelSort = "Model IN($modelArr)"; } else { $modelArr = ""; $modelSort = ""; } } else { $yearArr = ""; $yearSort = ""; $where = ""; } if(isset($_POST['Color'])){ $where = "WHERE"; if(isset($_POST['Year'])) { $and = "AND"; } else { $and = ""; } if(isset($_POST['Model'])) { $and = "AND"; } else { $and = ""; } $colorArr = "'" . implode("','", $_POST['Color']) . "'"; $colorSort = "Color IN($colorArr) $and"; if(isset($_POST['Year'])){ $yearArr = "'" . implode("','", $_POST['Year']) . "'"; $yearSort = "Year IN($yearArr)"; } else { $yearArr = ""; $yearSort = ""; } if(isset($_POST['Model'])){ $modelArr = "'" . implode("','", $_POST['Model']) . "'"; $modelSort = "Model IN($modelArr)"; } else { $modelArr = ""; $modelSort = ""; } } else { $colorArr = ""; $colorSort = ""; $where = ""; } if(isset($_POST['Model'])){ $where = "WHERE"; if(isset($_POST['Color'])) { $and = "AND"; } else { $and = ""; } if(isset($_POST['Year'])) { $and = "AND"; } else { $and = ""; } $modelArr = "'" . implode("','", $_POST['Model']) . "'"; $modelSort = "Model IN($modelArr) $and"; if(isset($_POST['Color'])){ $colorArr = "'" . implode("','", $_POST['Color']) . "'"; $colorSort = "Color IN($colorArr)"; } else { $colorArr = ""; $colorSort = ""; } if(isset($_POST['Year'])){ $yearArr = "'" . implode("','", $_POST['Year']) . "'"; $yearSort = "Year IN($yearArr)"; } else { $yearArr = ""; $yearSort = ""; } } else { $modelArr = ""; $modelSort = ""; $where = ""; } $querySort = "$yearSort $colorSort $modelSort"; $query = "SELECT * FROM vehicles $where $querySort $sort"; // create the query object $sql = mysql_query($query); // Pagination // Logic $nr = mysql_num_rows($sql);// Get total number of rows if(isset($_GET['pn'])) { $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); } else { $pn = 1; } $itemsPerPage = 10; $lastPage = ceil($nr / $itemsPerPage); if ($pn < 1) { $pn = 1; } else if ($pn > $lastPage) { $pn = $lastPage; } $centerPages = ""; // Initialize Variable $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; }$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; $sql2 = mysql_query("$query"); // End Logic // Pagination Display $paginationDisplay = ""; if ($lastPage !="1") { $paginationDisplay .='Page <strong>' . $pn . '</strong> of ' . $lastPage . ' <img src="images/clearImage.gif" width="48" height="1" alt="Spacer" />'; if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } $sql2 = mysql_query("$query"); $dynamicList = '<table border="0" cellpadding="10">'; $productCount = mysql_num_rows($sql2); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql2)){ $id = $row["id"]; $stockNumber = $row["StockNumber"]; $status = $row["Status"]; $gasType = $row["GasType"]; $year = $row["Year"]; $make = $row["Make"]; $model = $row["Model"]; $category = $row["Category"]; $transmission = $row["Transmission"]; $engineSize = $row["EngineSize"]; $color = $row["Color"]; $internetPrice = $row["InternetPrice"]; $driveTrain = $row["DriveTrain"]; $msrp = $row["MSRP"]; $internetSpecial = $row["InternetSpecial"]; $dateCreated = strftime("%b %d, %Y", strtotime($row["DateCreated"])); $comments = $row["VehicleComments"]; $options = $row["Options"]; $shortComments = substr($options, 0, 50); $detailSummary = '' . $stockNumber . ', ' . $color . ', ' . $gasType . ', ' . $driveTrain . ', ' . $shortComments . ''; $dynamicList .= '<tr><td>' . $year . ' ' . $make . ' ' . $model . ' ' . $detailSummary . ' $' . $internetPrice . '</td>'; } } else { $dynamicList = "We don't have any items in our store yet"; } $dynamicTable .= '</tr></table></form>'; mysql_close(); ?> <?php include 'storescripts/connect_to_mysql.php'; $sql = mysql_query("SELECT Color FROM vehicles GROUP BY Color"); $i = 0; $dynamicTable = '<table border="0" cellpadding="10"><strong>Color</strong>'; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $color = $row["Color"]; if($i % 2 == 0) { $dynamicTable .= "<tr><td><input name='Color[]' type='checkbox' value='" . $color . "' />" . $color . "</td>"; } else { $dynamicTable .= "<td><input name='Color[]' type='checkbox' value='" . $color . "' />" . $color . "</td>"; } $i++; } $dynamicTable .= '</tr></table>'; ?> <?php include 'storescripts/connect_to_mysql.php'; $sql = mysql_query("SELECT Model FROM vehicles GROUP BY Model"); $i = 0; $dynamicModel = '<table border="0" cellpadding="10"><br /><strong>Model</strong>'; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $model = $row["Model"]; if($i % 2 == 0) { $dynamicModel .= '<tr><td><input name="Model[]" type="checkbox" value="' . $model . '" />' . $model . '</td>'; } else { $dynamicModel .= '<td><input name="Model[]" type="checkbox" value="' . $model . '" />' . $model . '</td>'; } $i++; } $dynamicModel .= '</tr></table>'; ?> <?php include 'storescripts/connect_to_mysql.php'; $sql = mysql_query("SELECT Year FROM vehicles GROUP BY Year"); $i = 0; $dynamicYear = '<table border="0" cellpadding="10"><strong>Year</strong>'; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $year = $row["Year"]; if(isset($_POST['Year'])); { if($_POST['Year'] == $year) { $check = 'checked'; } else { $check = ''; } } if($i % 2 == 0) { $dynamicYear .= "<tr><td><input id='Year[]' name='Year[]' type='checkbox' " . $check . " value='" . $year . "' />" . $year . "</td>"; } else { $dynamicYear .= "<td><input id='Year[]' name='Year[]' type='checkbox' " . $check . " value='" . $year . "' />" . $year . "</td>"; } $i++; } $dynamicYear .= '</tr></table>'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Jay GMC Commercial - <?php echo $Year; ?><?php echo $Make; ?><?php echo $Model; ?> in Columbus, GA</title> </head> <body> <table width="100%" border="0" cellpadding="10"> <tr> <td width="64%"><h3><?php echo $query; ?> <br />PhP Grid Layout <br /><?php echo $yearSort; ?><?php echo $yearArr; ?></h3> </td> <td width="36%" align="right">Sort By:<form id="order" name="form1" method="get" action=""> <label for="order"></label> <select name="order" id="order"> <option value="ORDER BY Year ASC" <?php echo $selYa; ?>>Year (Low - High)</option> <option value="ORDER BY Year DESC" <?php echo $selYd; ?>>Year (High - Low)</option> <option value="ORDER BY Model ASC" <?php echo $selMa; ?>>Model (A - Z)</option> <option value="ORDER BY Model DESC" <?php echo $selMd; ?>>Model (Z - A)</option> </select> <input name="Submit" type="submit" value="Submit" /> </form></td> </tr> </table> <form action="sorttest.php" method="post" name="sort"> <table width="100%" border="1" cellpadding="10"> <tr align="left" valign="top"> <td width="24%"><input name="submit1" type="submit" /> <br /> <br /> <?php echo $dynamicTable; ?><br /> <?php echo $dynamicModel; ?><br /> <?php echo $dynamicYear; ?><br /></td> <td width="76%"><?php echo $dynamicList; ?></td> </tr> </table> </form> </body> </html> Thanks again! My table looks like this.. `guns_id` int(255) NOT NULL auto_increment, `guns_name` varchar(255) collate latin1_general_ci NOT NULL, `guns_price` int(255) NOT NULL, PRIMARY KEY (`guns_id`) I want to add a product key that is unique through out the whole database as I have other products other than guns aswell. Hi. This question is building off of things you all helped me with earlier in my other two threads. (I go no sleep last night, so sorry if my thinking is a bit off!) Now that I know how to create a gallery page - as far as HTML goes - to display a listing of free add-on items you get when you subscribe, I need to extend those concepts to my next project. I need to create a product catalog page for my e-commerce site. (Not sure if there is a better name?) This is the page you would see if you went to an e-commerce site and started shopping. At the top of the page would be my company mast. And beneath that, on the left side of the screen would be a menu listing different areas of my online store. And to the right, would be the area where you see the actual products. (And I would be using the same techniques to display items on the right hand side as I did in my earlier gallery. So here is where I could use some hep with the logic of this page... Let's say my website is located at www.mystore.com And in the left menu bar, I have these categories: Music, TV Shows, Movies, Gear And in the right pane I want to display items for the chosen section. So if you chose "Music", I am thinking the hyperlink behind it might read; www.mystore.com/music/ with a mod_rewrite to www.mystore.com?category=music And then I would have PHP code that would fire when the page is reloaded to www.mystore.com?category=music and it would query MySL and display all music related products in the right pane. (Note: It is understood I am only using HTML and PHP with no Javascript.) How does the above approach sound?
I am a php programmer but I am not so good with XML files. For a price comparison website, I need to parse the Amazons XML feed to store product data into the database. Can anyone please help me to find out such a simple script to parse Amazon XML product feed??? (Actually, I need each product data in array to be stored into the database) Thank you in advance. I'm trying to make one big array with my websites menu that has the categorys and the products i'm using code i found at http://www.phpfreaks.com/forums/index.php?topic=326419.msg1536842#msg1536842 its working fine till i try get the sub category and its products into the array $cats = array( 0 => array( 'categoryID' => 1, 'name' => 'Menu', 'parent' => 0) ,1 => array( 'categoryID' => 50, 'name' => 'Takeaway', 'parent' => 60) ); //root of the category $categorys = array( 1 => array( 1 => array( 'categoryID' => 6 , 'name' => 'Breads' , 'parent' => 1 ) ,0 => array( 'categoryID' => 2 , 'name' => 'Drinks' , 'parent' => 1 ) ,2 => array( 'categoryID' => 7 , 'name' => 'Salads' , 'parent' => 1 ) ) ,2 => array( 0 => array( 'categoryID' => 4 , 'name' => 'Tea' , 'parent' => 2 ) ,1 => array( 'categoryID' => 18 , 'name' => 'Coffee' , 'parent' => 2 ) ) ); // the category themselfs $product = array(6 => array( 0 => array('productID' => 1, 'categoryID' => 6,'name' => 'Plain Bread', 'description' => 'description') ,1 => array('productID' => 2, 'categoryID' => 6, 'name' => 'Garlic Bread', 'description' => 'description') ) ,7 => array( 0 => array('productID' => 44, 'categoryID' => 7, 'name' => 'Garden Salad', 'description' => 'description') ,1 => array('productID' => 45, 'categoryID' => 7, 'name' => 'Greek Salad', 'description' => 'description') ) ,4 => array( 0 => array('productID' => 74, 'categoryID' => 4, 'name' => 'Green Tea', 'description' => 'description') ) ,18 => array( 0 => array('productID' => 75, 'categoryID' => 18, 'name' => 'Espresso', 'description' => 'description') ) ); // the products if(is_array($cats)) { foreach($cats as $cat) { if(is_array($categorys[$cat['categoryID']])) { foreach($categorys[$cat['categoryID']] as $category) { if(is_array($categorys[$category['categoryID']])) { foreach ($categorys[$category['categoryID']] as $subcat){ $subcat['product'] = $product[$subcat['categoryID']]; $subprod[] = $subcat; //have tryed using parent $subprod[$subcat['parent']] but it over rides it self each time } } $category['product'] = $product[$category['categoryID']]; $category['subcategory'] = $subprod; // here is where I'm having problem $this_category[] = $category; } } if(!empty($this_category)){ $ncategory[] = array($cat,$this_category); } $this_category = array(); } } print_r($ncategory); thank you for your time sorry for any spelling or grammar errors I have a task that seems to be complex.
Short Description: currently users of the application I am hired to develop have two steps to do when using the app:
1. Select a Product Line (A, B, C, D)
2. Select input parameters for that product line - all product lines have simlar "Main" input parameters, but also each line has its own special features that can be selected.
3. Selections for that product line are shown - the result is a long table or options for that particular product line. Things like price, discounts, product specifications, etc.
What the users want now is this:
1. Select input parameters (not sure how to handle individual product lines special parameters yet)
2. Selections for all product lines are shown
The code base is legacy code, with code thrown around everywhere. One idea me and my coworkers have been considering is a complete rewrite, since it will help us with writing tighter code, and do what the customer wants. But that will also take time, and there is no spec. The spec is in the code mess.
Another one is I am considering now is a "merge". Somehow merge the product lines, since we have the separate product modules (A, B, C, D), there must be a way to consider maybe extending one to include the others, or somehow get me to the end result -- allow users to see selections for all product lines.
Do you have any experience, any suggestions on how to do this? I know this needs details, and details are in my code that you don't see, and most likely won't have the time to read and understand anyway.
But I am looking for any ideas or encouragement though that may help. And my question is -- is there any kind of procedure or technique or something to deal with the problem I am facing -- merging several separate yet similar modules into one single merged module. How do I approach this, what are some things that could help, etc. That's what I'm looking for.
Hi All, I am creating a page where a customer can create a new order from a list of items. All the data is stored in a MySQL database and is accessed by PHP. What I am trying to achieve is the following: Starting with one row as shown below: The customer can then select a product from the list and the details appear in the following rows as shown he The customer should then be able to add another row by pressing the + button or delete that row by pressing the - button. At the moment I have got the system to work as far as one row goes with the data being placed into the rows using AJAX. I have then tried to add new rows/delete rows etc. but have had little success and have pretty much hit a brick wall. I would greatly appreciate it if someone could take a look and point me in the right direction! Thanks! The code for the above project is shown below: neworder.php Code: [Select] <table id="dataTable" style="margin-left:22px;margin-top:30px;"> <thead> <tr class="odd"> <th style="text-align:center;"scope="col" abbr="Add/Delete"><INPUT style="width:25px" TYPE="button" VALUE="+" onClick="addRow('dataTable')"/></th> <th scope="col" abbr="Qty">Quantity</th> <th scope="col" abbr="Code">Product Code</th> <th scope="col" abbr="Argus Code">Argus Product Code</th> <th scope="col" abbr="Desc">Description</th> <th scope="col" abbr="Rate">Rate</th> <th scope="col" abbr="Amount">Amount</th> <th scope="col" abbr="VAT">VAT</th> </tr> </thead> <tbody id="txtHint"> <tr class="odd"> <td style="text-align:center;"><INPUT style="width:25px" TYPE="button" VALUE="-" onClick="deleteRow('dataTable')"></td> <td><input style="width:40px" type="text" value="1" name="quantity<? echo $num; ?>"/></td> <td><form><select name="products" onchange="showProductList(this.value, <?php echo getCustNum($custname); ?>)"><option value="">Select a product:</option><?php $products = mysql_query("SELECT * FROM products"); while($getproducts = mysql_fetch_array($products)){ echo '<option value='.$getproducts['ProductCode'].'>'.$getproducts['ProductCode'].' - '.$getproducts['ArgusProductCode'];} ?></select></form></td> <td><?php echo $argusproductcode; ?></td> <td><?php echo $description; ?></td> <td style="text-align:right;"><? echo $rate; ?></td> <td style="text-align:right;"><? //echo $amount; ?></td> <td><?php echo $vat; ?></td> </tr> </tbody> <tfoot> <tr><td></td> <td></td> <td></td> <td></td> <td>Sub-total</td> <td style="text-align:right;"><?php echo getSubTotal($ponum); ?></td> <td></td> <td></td> </tr> <tr><td></td> <td></td> <td></td> <td></td> <td>VAT</td> <td style="text-align:right;"><?php echo getVATCost($ponum); ?></td> <td></td> <td></td> </tr> <tr><td></td> <td></td> <td></td> <td></td> <td>TOTAL</td> <td style="text-align:right;">£<?php echo number_format((getSubTotal($ponum)+getVATCost($ponum)), 2, '.', ''); ?></td> <td></td> <td></td> </tr> </tfoot> </table> JS/XML for the data to be placed in the rows: Code: [Select] function showProductList(str, str2) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getproductlist.php?q="+str+"&c="+str2,true); xmlhttp.send(); } getproductlist.php <?php include("db.php"); include("functions.php"); $q = $_GET["q"]; $c = $_GET["c"]; $productcode = $q; $q1 = getProductID($productcode); $counter = 1; $result = mysql_query("SELECT * FROM products WHERE ProductCode = '$productcode'"); $result2 = mysql_query("SELECT * FROM customerPrices WHERE CustNum = '$c' AND ProductID = '$q1'"); while($row = mysql_fetch_array($result)) { while($row2 = mysql_fetch_array($result2)) { //while(counter > 0) //{ $argusproductcode = $row['ArgusProductCode']; $description = $row['Description']; $rate = $row2['Rate']; $vat = $row2['VAT']; echo '<tr class="odd"> <td style="text-align:center;"><input style="width:25px" type="button" value="-" onClick="deleteRow(\'dataTable\')"></td> <td><input style="width:40px" type="text" value="1" name="quantity'.$num.'"/></td> <td><form>'.$productcode.'</form></td> <td>'.$argusproductcode.'</td> <td>'.$description.'</td> <td style="text-align:right;">'.$rate.'</td> <td style="text-align:right;">'.$amount.'</td> <td>'.$vat.'</td> </tr>'; //} } } ?> JS for Adding/Deleting Rows (Although some of this is probably garbage!) Code: [Select] function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; rowCount = rowCount - 3; var row = table.insertRow(rowCount); row.id = "row"; document.getElementById("row").className = "odd"; var cell1 = row.insertCell(0); var delbutton = document.createElement("input"); delbutton.type = "button"; delbutton.style.textAlign = "center"; delbutton.style.width = "25px"; delbutton.value = "-"; cell1.appendChild(delbutton); var cell2 = row.insertCell(1); var quantity = document.createElement("input"); quantity.type = "text"; quantity.style.width = "40px"; quantity.value = "1"; cell2.appendChild(quantity); var cell3 = row.insertCell(2); var cell4 = row.insertCell(3); var cell5 = row.insertCell(4); var cell6 = row.insertCell(5); var cell7 = row.insertCell(6); var cell8 = row.insertCell(7); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=1; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } Thanks again! Hi there i have a big issues which is starting to cause me lots of stress. I have two tables one which is products and contains the following below and the other which is additionalCategories which the contains is also below. products id name image1 image2 image3 image4 image5 description department category subcategory Price additonalCategories id departmentID categoryID subcategoryID productID i have made a products upload script to my site where i can add products too it saves the category and subcategory id's in the fields above then if i wish to add the product to additional categories i do so and again this adds all the data to the addiotnalCategories table. however i can seems to be able to display this on the view products page i tried the below code but get no luck Code: [Select] <?php session_start(); $username=$_SESSION['username']; include_once"../includes/db_connect.php"; $cat=$_GET['cat']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $query("SELECT products.name AS name, products.price AS price, addtionalCategories.productID AS productID FROM products, addtionalCategories WHERE category='$cat' AND products.id = addtionalCategories.productID"); while($fetch=mysql_fetch_object($query)){ echo"$fetch->name"; } ?> </body> </html> i need a way in which on the page it check the category id then finds all the products that are saved in the additionalCategories table then to find the data saved in the products table such as the name and price etc please any help will be appreciated thank you for reading Hello, I need to hide products with same title from WooCommerce shop page and i'm trying to achieve that with a custom loop. For example i have 5 products called "Plex" and the only diferrence between them is the SKU field and the color. I don't care which of the same product will be displayed in the shop page, i just want to display only one of all these products. I created a loop which is working and does hide products with same name but i have a problem. If i set posts_per_page=8 it shows less because it counts the hidden products also. $args = array( 'post_type' => 'product', 'posts_per_page' => 8 ); $query = new WP_Query($args); $list = array(); while ($query->have_posts()) : $query->the_post(); if(in_array(get_the_title(), $list)){ continue; } $list[] = get_the_title(); ?> <li><?php wc_get_template_part( 'content', 'product' ); ?></li> <?php endwhile; wp_reset_postdata(); P.S. I don't want to remove these products, i just want to hide them from shop loop! Any ideas what is the problem with the loop? Is there a better way to achieve that? |