PHP - Php Navigation Bar And Product List Problems
Similar TutorialsHello, 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! 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 Hi, I am just wondering if there is any way that I can link Google Maps which will then link to my product stocklist - see attachment for what I am trying to achieve. Please let me know if this is possible. Thanks, I would like to customize my product-list page to display all my products in a grid with an ADD TO CART option for each product. That means i have two ADD TO CART button on the site, in productDetail.php there is a ADD TO CART button original from the tutorial, i need customize another ADD TO CART button on productList.php. Does anyone know how to accomplish this customization? . Please help because I am stuck with the coding for 3weeks Tutorial site: http://www.phpwebcommerce.com/plaincart/index.php productDetail.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $product = getProductDetail($pdId, $catId); // we have $pd_name, $pd_price, $pd_description, $pd_image, $cart_url extract($product); ?> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td align="center"><img src="<?php echo $pd_image; ?>" border="0" alt="<?php echo $pd_name; ?>" width="230" height="170"></td> <td valign="middle"> <strong><?php echo $pd_name; ?></strong><br> Price : <?php echo displayAmount($pd_price); ?><br> <?php // if we still have this product in stock // show the 'Add to cart' button if ($pd_qty > 0) { ?> <input type="button" name="btnAddToCart" value="Add To Cart >" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton"> <?php } else { echo 'Out Of Stock'; } ?> </td> </tr> <tr align="left"> <td colspan="2"><?php echo $pd_description; ?></td> </tr> </table> productList.php: Code: [Select] <?php if (!defined('WEB_ROOT')) { exit; } $productsPerRow = 2; $productsPerPage = 8; //$productList = getProductList($catId); $children = array_merge(array($catId), getChildCategories(NULL, $catId)); $children = ' (' . implode(', ', $children) . ')'; $sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id FROM tbl_product pd, tbl_category c WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children ORDER BY pd_name"; $result = dbQuery(getPagingQuery($sql, $productsPerPage)); $pagingLink = getPagingLink($sql, $productsPerPage, "c=$catId"); $numProduct = dbNumRows($result); // the product images are arranged in a table. to make sure // each image gets equal space set the cell width here $columnWidth = (int)(100 / $productsPerRow); ?> <table width="100%" border="0" cellspacing="0" cellpadding="20"> <?php if ($numProduct > 0 ) { $i = 0; while ($row = dbFetchAssoc($result)) { extract($row); if ($pd_thumbnail) { $pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail; } else { $pd_thumbnail = WEB_ROOT . 'images/no-image-small.png'; } if ($i % $productsPerRow == 0) { echo '<tr>'; } // format how we display the price $pd_price = displayAmount($pd_price); echo "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id" . "\"><img src=\"$pd_thumbnail\" border=\"0\" width=\"230\" height=\"170\"><br>$pd_name</a><br>Price : $pd_price<br>"; // format display add to cart echo "<input type=\"button\" name=\"btnAddToCart\" value=\"Add To Cart >\" onClick=\"window.location.href='<?php echo $cart_url;?>';\" >"; // if the product is no longer in stock, tell the customer if ($pd_qty <= 0) { echo "<br>Out Of Stock"; } echo "</td>\r\n"; if ($i % $productsPerRow == $productsPerRow - 1) { echo '</tr>'; } $i += 1; } if ($i % $productsPerRow > 0) { echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '"> </td>'; } } else { ?> <tr><td width="100%" align="center" valign="center">No products in this category</td></tr> <?php } ?> </table> <p align="center"><?php echo $pagingLink; ?></p> Product-functions.php: Code: [Select] <?php require_once 'config.php'; /********************************************************* * PRODUCT FUNCTIONS **********************************************************/ /* Get detail information of a product */ function getProductDetail($pdId, $catId) { $_SESSION['shoppingReturnUrl'] = $_SERVER['REQUEST_URI']; // get the product information from database $sql = "SELECT pd_name, pd_description, pd_price, pd_image, pd_qty FROM tbl_product WHERE pd_id = $pdId"; $result = dbQuery($sql); $row = dbFetchAssoc($result); extract($row); $row['pd_description'] = nl2br($row['pd_description']); if ($row['pd_image']) { $row['pd_image'] = WEB_ROOT . 'images/product/' . $row['pd_image']; } else { $row['pd_image'] = WEB_ROOT . 'images/no-image-large.png'; } $row['cart_url'] = "cart.php?action=add&p=$pdId"; return $row; } ?> any help will be greatly appreciated This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=343748.0 hello this is my first time posting so i'm sorry if i word this wrong or it is a stupid question. i have a simple database made up with a product table with five fields; id, url, name, description, and price. also a categories table with five fields; id, parent_id, siteurl, name, and description. i have everything up and running,but i can't figure out how to pass the product id as a parameter. right now i have "example.php" but i need "example.php?id=1" here is what my code looks like indextest.php Code: [Select] <?php error_reporting(0); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Car Dealer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $usr = "root"; $pwd = ""; $db = "mymarket"; $host = "localhost"; //connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } $category = ""; // setup SQL statement $SQL = " SELECT * FROM categories "; $SQL = $SQL . " WHERE parent_id = '0' "; // execute SQL statement $retid = mysql_db_query($db, $SQL, $cid); // check for errors if (!$retid) { echo( mysql_error()); } else { ?> <div id="layout"> <div id="titlebg"> <div class="title">CAR</div> <div class="title1">DEALER</div> <div class="title2">WE HAVE</div> <div class="title3">THE BEST CARS</div> <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div> </div> <hr id="hrline" /> <div id="gradientbg"> <div id="links"> <h2> <?php // display results echo ("<p><dt><b>$category</b><br>\n"); while ($row = mysql_fetch_array($retid)) { $siteurl = $row["siteurl"]; $name = $row["name"]; echo ("<dd><a href='$siteurl'>$name</a></dd>\n<br>"); } echo ("</dt></p>"); } ?> <h2/> </div> <div id="header"></div> </div> <div id="bodypart"> <div id="catalogue"> <div class="cat">CATALOGUE</div> <div id="cat1"></div> <div id="car1"></div> <div id="cat2"></div> <div id="car2"></div> </div> <div id="line"></div> <div id="ourservices"> <div class="our">OUR SERVICES</div> <div id="pic1"></div> <div class="lorem">Lorem ipsum</div> <div class="txt">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div> </div> <div id="line1"></div> <div id="aboutus"> <div class="abt">ABOUT US</div> <div id="pic2"></div> <div class="lorem1">Lorem ipsum</div> <div class="txt1">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div> </div> </div> <hr id="hrline1" /> <div class="foottxt">Copyright © Cars. Design by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>.</div> </div> </body> </html> and i would like to link that to this next file att.php Code: [Select] <?php error_reporting(0); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Smartphone Dealer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $usr = "root"; $pwd = ""; $db = "mymarket"; $host = "localhost"; //connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } $category = ""; // setup SQL statement $SQL = " SELECT * FROM categories "; $SQL = $SQL . " WHERE id ='4' OR id = '5' OR id = '6' "; ?> <div id="layout"> <div id="titlebg"> <div class="title">SMARTPHONE</div><br> <div class="title1">DEALER</div> <div class="title2">WE HAVE</div> <div class="title3">NO CONTRACT SMARTPHONES</div> <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div> </div> <hr id="hrline" /> <div id="gradientbg"> <h3> <?php // execute SQL statement $retid = mysql_db_query($db, $SQL, $cid); // check for errors if (!$retid) { echo( mysql_error()); } else { // display results echo ("<p><dt><b>$category</b><br>\n"); while ($row = mysql_fetch_array($retid)) { $siteurl = $row["siteurl"]; $description = $row["description"]; echo ("<dd><a href='$siteurl'>$description</a></dd>\n<br>"); } echo ("</dt></p>"); } ?> </div> <h3> </div> <hr id="hrline1" /> <div class="foottxt">Copyright © Nathan Hein. Template by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>. <br> DISCLAIMER: This website was designed for a school project and is not intended for commercial use of any kind.</div> </div> </body> </html> i know i probably have a lot of problems with this code, but the one i can't figure out is passing the parameter and i have been looking at forums, websites, w3schools, everywhere. i;m just not grasping the concept of how to make it work with this. thank you so much for any input hi i have generated a product list from a mysql table called product_list, once i enter a new product in to the table the product will be shown in the generated list and the list will grow and the table grows. and i want to allow user the edit/delete/save the products from the generated table, i have no idea how to do it and what is the algorithmic idea to do it so. here is the php and the html code. <!--Body container for creating a new product in to the list--> <div class="body_orderviewform"> <form name="form1" method="post" action="upload_file.php" enctype="multipart/form-data"> <p> <label for="user_id">User ID:</label> <input type="text" name="user_id" id="user_id"> <label for="customer_name">Customer Name:</label> <input type="text" name="customer_name" id="customer_name"> <label for="customer_family">Customer_family</label> <input type="text" name="customer_family" id="customer_family"> <label for="freelancer_name">Purchaser:</label> <input name="freelancer_name" type="text" id="freelancer_name"> <? if (isset($_COOKIE['picAdd'])) echo $_COOKIE['picAdd'];?> </p> <!------------------------------------------------------------------------------------------------------- for generating the list --> <div class="div.neworder_list" > <div class="div.neworder_listheader" align="center"> <table width="637" border="1" > <tr> <td width="193"><label for="link">link:</label> <label for="link_new"></label> <input type="text" name="link_new" id="link_new"></td> <td width="202"><label for="unitprice">Unit Price:</label> <label for="Unit_price_new"></label> <input type="text" name="Unit_price_new" id="Unit_price_new"></td> <td width="220"><label for="qty">Quantity:</label> <label for="quantity_new"></label> <input type="text" name="quantity_new" id="quantity_new"></td> </tr> <tr> <td><label for="express">Express Fee:</label> <label for="express_new"></label> <input type="text" name="express_new" id="express_new"></td> <td><label for="commission_new">Commission:</label> <input type="text" name="commission_new" id="commission_new"></td> <td><label for="customer_description">Description</label> <label for="description_new"></label> <textarea name="description_new" id="description_new" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td colspan="2">Picture Upload: <input type="hidden" name="<?php echo ini_get("session.upload_progress.name");?>" value="123" /> <input name="file" type="file" autofocus="autofocus"/> <br /> </tr> <tr> <td colspan="3"><input type="reset" name="reset" id="reset" value="Reset"> <input type="submit" name="submit" id="submit" value="Submit The Product"></td> </tr> </table> </form> </div> <div class="neworder_listview"> <p> <form action="" method="post" name="list"> <input type="submit" name="del" id="del" value="Save"> <input type="submit" name="save" id="save" value="Del"> </p> <table width="1022" border="1" align="center"> <tr> <th width="24" scope="col"> </th> <th width="24" scope="col">Row#</th> <th width="137" scope="col">Manager</th> <th width="137" scope="col">Purchaser Desc</th> <th width="40" scope="col"><p>Link</p> <p>/Ссылки</p></th> <th width="53" scope="col">ФОТО</th> <th width="50" scope="col">Unit Price/Цена за еденицу товара</th> <th width="46" scope="col">Quantity/ Кол-во</th> <th width="138" scope="col">Total Unit Price/ Общая цена</th> <th width="89" scope="col">Express/Доставка по Китаю</th> <th width="119" scope="col">Description/Описание</th> <th width="89" scope="col">ADDITIONAL LINKS/ЗAMЕНЫ</th> </tr> <?php $username = "my username"; $password = "my pass"; $database = "userinfo"; $link = mysql_connect("localhost", "$username", "$password"); if(!$link) {echo("Failed to establish connection to mysql server"); exit();} $status = mysql_select_db($database); $query = "SELECT * FROM order_list"; $result = mysql_query($query); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $field1_name=mysql_result($result,$i,"admin_st"); $field2_name=mysql_result($result,$i,"freelancer_st"); $field3_name=mysql_result($result,$i,"link"); $field4_name=mysql_result($result,$i,"picture"); $field5_name=mysql_result($result,$i,"unitprice"); $field6_name=mysql_result($result,$i,"qty"); $field7_name=mysql_result($result,$i,"express"); $field8_name=mysql_result($result,$i,"customer_st"); $i++; } ?> <?php $i=0; $row=1; while ($i < $num) { $f1=mysql_result($result,$i,"admin_st"); $f2=mysql_result($result,$i,"freelancer_st"); $f3=mysql_result($result,$i,"link"); $f4=mysql_result($result,$i,"pic_address"); $f5=mysql_result($result,$i,"unitprice"); $f6=mysql_result($result,$i,"qty"); $f7=mysql_result($result,$i,"express"); $f8=mysql_result($result,$i,"customer_st"); $totao_unit_price = $f5*$f6; ?> <tr> <td><input type="checkbox" name="del_chbox" id="del_chbox"> <td><p><font face="Arial"><input name="row_txtbox" type="text" id="row_txtbox" size="2" value="<?php echo $row; ?>"></font></td> <td><p><font face="Arial"> <textarea name="manager_txtbox" cols="10" id="manager_txtbox"><?php echo $f1; ?></textarea></font></td> <td><p><font face="Arial"> <textarea name="purchase_txtbox" cols="10" id="purchase_txtbox"><?php echo $f2; ?></textarea> </font></td> <td><font face="Arial"><a href="<?php $f3 ?>" target="_blank"><?php echo $f3; ?></a></font></td> <td><font face="Arial"><img src="<?php echo $f4;?>" width="100" align="middle"100></font></td> <td><font face="Arial"><input name="unitprice_txtbox" type="text" id="unitprice_txtbox" size="2" value="<?php echo $f5; ?>"></font></td> <td><font face="Arial"> <input name="qty_txtbox" type="text" id="qty_txtbox" size="2" value="<?php echo $f6; ?>"></font></td> <td><p><font face="Arial"><?php echo $totao_unit_price; ?></font></td> <td><p><font face="Arial"><input name="express2" type="text" id="express3" size="2" value="<?php echo $f7; ?>"></font></td> <td><p><font face="Arial"> <textarea name="custdesc_txtbox" cols="20" id="custdesc_txtbox"><?php echo $f8; ?></textarea></font></td> <td><input name="express2" type="text" id="express3" size="2" value="<?php echo "new link" ?>"></td> </tr> <p> <?php $i++; $row++; } ?> </table> </p> <p> </p> </form> I am wanting to create a basic product listing page for a product category called "Belts". My latest attempt was this, but I got an error: PHP Code: Code: [Select] $query = "select * from products"; $result = mysql_query($query); while($row=mysql_fetch_assoc($result)) { print ".$row['name'] where category = 'Belts'.$row['colour'] where category = 'Belts'"; } Quote PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING This is what my MySQL table looks like: http://i54.tinypic.com/2j1si8w.png I image what I am trying to do will print "Somename Black, ProductName2 Brown"? I'm not really interested in styling at the moment, I just want to see the PHP-MySQL work at the most basic level. I am unsure what the error cosde means. Can anyone see a fault in my code? 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! Hi, I'm building a dynamic site for a college project (a CMS) and have been using a Lynda tutorial. When the user clicks on a subject, the sub menu appears for the (a UL with a UL), so there is an 'accordian effect'. However, when I click on one of the page links in the sub menu, the content for that page appears, but the second UL containing the links to the pages dissapears. It only re-appears when I click back on the parent element (the subject link). I'd really appreciate some help. I've tried editing this code below but have had no joy: Code: [Select] function public_navigation($sel_subject, $sel_page, $public = true) { $output = "<ul class=\"subjects\">"; $subject_set = get_all_subjects($public); while ($subject = mysql_fetch_array($subject_set)) { $output .= "<li"; if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"index.php?subj=" . urlencode($subject["id"]) . "\">{$subject["menu_name"]}</a></li>"; if ($subject["id"] == $sel_subject['id']) { $page_set = get_pages_for_subject($subject["id"], $public); $output .= "<ul class=\"pages\">"; while ($page = mysql_fetch_array($page_set)) { $output .= "<li"; if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"index.php?page=" . urlencode($page["id"]) . "\">{$page["menu_name"]}</a></li>"; } $output .= "</ul>"; } } $output .= "</ul>"; return $output; } The code that precedes this is as follows: Code: [Select] function get_all_subjects($public = true) { global $connection; $query = "SELECT * FROM Subjects "; if ($public) { $query .= "WHERE visible = 1 "; } $query .= "ORDER BY position ASC"; $subject_set = mysql_query($query, $connection); confirm_query($subject_set); return $subject_set; } function get_pages_for_subject($subject_id, $public = true) { global $connection; $query = "SELECT * FROM pages "; $query .= "WHERE subject_id = {$subject_id} "; if ($public) { $query .= "AND visible = 1 "; } $query .= "ORDER BY position ASC"; $page_set = mysql_query($query, $connection); confirm_query($page_set); return $page_set; } function get_subject_by_id($subject_id) { global $connection; $query = "SELECT * "; $query .= "FROM Subjects "; $query .= "WHERE id=" . $subject_id ." "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); // REMEMBER: // if no rows are returned, fetch_array will return false if ($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } function get_page_by_id($page_id) { global $connection; $query = "SELECT * "; $query .= "FROM pages "; $query .= "WHERE id=" . $page_id ." "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); // REMEMBER: // if no rows are returned, fetch_array will return false if ($page = mysql_fetch_array($result_set)) { return $page; } else { return NULL; } } function get_default_page($subject_id) { // Get all visible pages $page_set = get_pages_for_subject($subject_id, true); if ($first_page = mysql_fetch_array($page_set)) { return $first_page; } else { return NULL; } } function find_selected_page() { global $sel_subject; global $sel_page; if (isset($_GET['subj'])) { $sel_subject = get_subject_by_id($_GET['subj']); $sel_page = get_default_page($sel_subject['id']); } elseif (isset($_GET['page'])) { $sel_subject = NULL; $sel_page = get_page_by_id($_GET['page']); } else { $sel_subject = NULL; $sel_page = NULL; } } function navigation($sel_subject, $sel_page, $public = false) { $output = "<ul class=\"subjects\">"; $subject_set = get_all_subjects($public); while ($subject = mysql_fetch_array($subject_set)) { $output .= "<li"; if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"edit_subject.php?subj=" . urlencode($subject["id"]) . "\">{$subject["menu_name"]}</a></li>"; $page_set = get_pages_for_subject($subject["id"], $public); $output .= "<ul class=\"pages\">"; while ($page = mysql_fetch_array($page_set)) { $output .= "<li"; if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"content.php?page=" . urlencode($page["id"]) . "\">{$page["menu_name"]}</a></li>"; } $output .= "</ul>"; } $output .= "</ul>"; return $output; } Hi, I am am looking to develop further the code below. This code allows me to display a left navigation bar with Main Links and then if you click a Main link, that link is listed first in the list and its' submenu appears below. For the majority of links in the navigation bar this is fine. But for about 2 of the Main links this basic navigation is not suitable. I need the navigation for 2 of the links to offer more depth. So, for example, if you click Accessories in: Shoes Trousers Shirts Accessories Looks like this if Accessories is clicked: Accessories Belts Cuff Links Wallets Shoes Trousers Shirts Looks like this if belts is clicked (Main link name changed and submenu changed): Accessories - Belts Brown leather Black Leather Multicolour Designs All casual All formal Shoes Trousers Shirts Looks like this is Brown Leather is clicked: Brown Leather Belts Armani Brown Leather Belt 32" Armani Brown Leather Belt 34" Hugo Boss Brown Leather Belt 32" Hugo Boss Brown Leather Belt 34" Shoes Trousers Shirts Currently the code does not allow for this depth in the navigation bar. Any ideas how it could be done? Do I need additional tables for each subcategory. How do I ensure the category clicked does not appear in the rest of the navigation bar, as in the code I have at the moment? Currently the code is: $res = mysql_query("SELECT * FROM categories"); while($row = mysql_fetch_array($res)) { $cats[$row['categoryid']] = $row['categoryname']; } if(isset($_GET['category'])) { $selcat = $_GET['category']; } if(isset($_GET['product'])) { $prod_info = mysql_fetch_array(mysql_query("SELECT * FROM products WHERE productid = ".$_GET['product'])); //Prod_Info now gets stored for use in the main display. $selcat = $prod_info['categoryid']; } if(isset($selcat)) { echo "<a href='categorylist.php?category=".$selcat."'>".$cats[$selcat]."</a>"; unset($cats[$selcat]); //Gets rid of it for later. $res = mysql_query("SELECT productid,name FROM products WHERE categoryid = ".$selcat); while($row = mysql_fetch_array($res)) { echo "<a href='product.php?product=".$row['productid']."'>".$row['name']."</a>"; } } foreach($cats AS $key => $cat) { echo "<a href='categoryview.php?category=".$key."'>".$cat."</a>"; } Thank you for looking at this post, Matt. 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); } ?> 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. 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. 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!! 🙂
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! 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 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 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?
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?
|