Jump to content
Larry Ullman's Book Forums

Bill

Members
  • Posts

    45
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Bill

  1. Sorting appears to be a problem with early browsers but with use of function x-y problem has been resolved with modern browsers. Click on link for more detailed info on numbers.sort() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FArray%2Fsort
  2. It's a typing error! Rafal says regarding errata on this webstie that on Page 247: var numbers = [1, 4, 3, 2]; numbers.sort(); // 4, 1, 3, 2 "For me it looks the better example will be [1, 14, 3, 2] and in old browsers the result will be 1, 14, 2, 3." See link: http://www.larryullman.com/books/modern-javascript-develop-and-design/errata/comment-page-1/
  3. I have been able to figure out how to get multiple checkboxes to work. After spending a couple of weeks studying similar programs from example 2, I was surprised that it only took a few minutes to do in terms of coding at the keyboard and not one error message! Parts of the code from the add_inventory script in admin section and cart.php only required small changes. However, it never occurred to me that ecommerce sites only use one item as part of payment process. After searching online for a solution I noticed one fellow said that a website is “flawed” if you cannot select more than one item. This information was in the search results and I did not click on the link. Anyway, I am not an expert here. I am only designing a non-ecommerce program for my own purposes and thus these multiple checkboxes are not part of a payment gateway at all. What I have been developing is a food program where I can select certain items from a list of categories and move them to another list like cart. The user interface is now more efficient and effortless as many products can be selected on one page to view, whereas previously this required many clicks. So thanks again as your instructions were easy to implement Larry.
  4. I think those tables will populate after providing appropriate merchant information such as your login id and transaction key. Your book should explain how to set up payment gateway and how to fully test the site using credit card details. This is how 1st edition takes care of payment process. As I do not have 2nd edition only the earlier 1st edition, I am unable to provide clarity as to how you can do it! Sorry.
  5. Try to ensure program is connecting to database as a lot of problems are related to this. .This may not be relevant but are you creating your own reg script or is the code you are using direct from downloaded code from Larry's website?
  6. It could go in the mysql statement of the script. I don't know for sure as I have the book with stored procedures.
  7. Hi all! My goal is to enhance the design of the sales program to enable the selection of many items or just one item that can be moved to the shopping cart using checkboxes. Have searched this site and on the net to solve problem in conjuction with studing lines of code in various programs listed in the book to gain clearer understanding.of problem. Here is list_sales.html with addition of checkbox code line. <?php // This page is included by sales.php. // This page displays the available sale products. // This page will make use of the query result $r. // The query returns an array of: description, image, sku, name, and stock. // Added later in Chapter 8: include ('./includes/product_functions.inc.php'); ?> <!-- box begin --> <div class="box alt"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="border-top"></div> </div> </div> <div class="border-left"> <div class="border-right"> <div class="inner"> <h2>Current Sale Items</h2> <form action="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/sales.php" method="post" accept-charset="utf-8"> <?php // Loop through each item: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<h3 id="' . $row['sku'] . '">' . $row['category'] . '::' . $row['name'] .'</h3> <div class="img-box"> <p><img alt="' . $row['name'] . '" src="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/products/' . $row['image'] . '" />' . $row['description'] . '<br />' . get_price('goodies', $row['price'], $row['sale_price']) . ' <strong>Availability:</strong> ' . get_stock_status($row['stock']) . '</p> <p><a href="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/cart.php?sku=' . $row['sku'] . '&action=add" class="button">Add to Cart</a></p> <td align="left"><input type="checkbox" name="item['.$row['sku'].']" id="item[' . $row['sku'] . ']" size="5" class="button" /> </td> </div>'; } ?> <div class="field"><input type="submit" value="Add Products" class="button" /></div> </fieldset> </form> </div> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"></div> </div> </div> </div> <!-- box end --> </div> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"></div> </div> </div> </div> <!-- box end --> And here is sale.php from from with inclusion of a for loop. <?php // This file is the sales page. // It lists every sales item. // This script is begun in Chapter 8. // Require the configuration before any PHP code: require ('./includes/config.inc.php'); // Include the header file: $page_title = 'Sale Items'; include ('./includes/header.html'); // Require the database connection: require (MYSQL); // Invoke the stored procedure: $r = mysqli_query ($dbc, 'CALL select_sale_items(true)'); if (mysqli_num_rows($r) > 0) { include ('./views/list_sales.html'); } else { include ('./views/noproducts.html'); } // run through items added to cart: if (isset($_POST['items']) && is_array($_POST['items'])) { // Loop through each submitted value: foreach ($_POST['items'] as $sku => $qty) { // Validate the added quantity: if (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 1))) { // Parse the SKU: list($type, $id) = parse_sku($sku); $items = (empty($_POST['items'][$sku]))? NULL: $_POST['items']['$sku']; } } // End of IF. } // End of FOREACH. // Include the footer file: include ('./includes/footer.html'); ?> Thank you in advance! Windows 7 Xampp 1.8.3 php version 5.5.11 phpMyAdmin 4.1.12 Mysql Server 5.6
  8. Hi - sorry for the delayed response but I have made a bit of progress. I have managed to get the dropdown selection list to appear in cart.html but I can't select and pass each size variable to the url: $sizes = array(0.25, 0.50, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0); $size = 'size[' . $row['sku'] . ']'; echo '<td align="center"><select name="size[' . $row['sku'] . ']" value="size">'; echo '<option value="size[' . $row['size'] . ']">Choose</option>'; foreach ($sizes as $id => $size) { echo '<option value="$id ">' ; if ($size == $id) echo ' selected="selected"'; echo "$size</option>" ; } echo '</select>'; And here is the part that transfers the size variable: <td align="center" width="26%"><p><a href="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/cart.php?sku=' . $row['sku'] . '&action=move&qty='.$row['quantity']. '&action=move&size=' . $size . '">Add to Cart</a></p></td> The only problem is that the last value in the array, that is, 2.0 is only passed. Nevertheless, size=2 does appear in the url but no other variable in the array can be selected or sent via the url? Thanks for your suggestions!
  9. I have been able to echo the $uid variable in the coffee cart.php script when the stored procedure is being called. However, if the mysql query get_shopping_cart_contents is running in a non-stored procedure environment, an error message saying "your shopping cart is empty!" occurs. This error message appears to suggest that the syntax of the mysql query in a non-stored procedure environment is at fault but I am not sure that is the case. Here is the error message: An error occurred in script 'C:\xampp\htdocs\larryullman\Sites\ecom_book\ex2\html\cart.php' on line 117: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array ( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given [2] => C:\xampp\htdocs\larryullman\Sites\ecom_book\ex2\html\cart.php [3] => 117 [4] => Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( [sESSION] => 762d4f78b298d60a1d5279e67a5db64e [__atuvc] => 1|27 ) [_FILES] => Array ( ) [_ENV] => Array ( ) [_REQUEST] => Array ( ) [_SERVER] => Array ( [MIBDIRS] => C:/xampp/php/extras/mibs [MYSQL_HOME] => \xampp\mysql\bin [OPENSSL_CONF] => C:/xampp/apache/bin/openssl.cnf [php_PEAR_SYSCONF_DIR] => \xampp\php [phpRC] => \xampp\php [TMP] => \xampp\tmp [HTTP_ACCEPT] => text/html, application/xhtml+xml, */* [HTTP_REFERER] => http://localhost/larryullman/Sites/ecom_book/ex2/html/cart.php [HTTP_ACCEPT_LANGUAGE] => en-AU [HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0) [HTTP_UA_CPU] => AMD64 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_HOST] => localhost [HTTP_CONNECTION] => Keep-Alive [HTTP_COOKIE] => SESSION=762d4f78b298d60a1d5279e67a5db64e; __atuvc=1%7C27 [PATH] => C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared; [systemRoot] => C:\windows [COMSPEC] => C:\windows\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC [WINDIR] => C:\windows [sERVER_SIGNATURE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost Port 80 [sERVER_SOFTWARE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 [sERVER_NAME] => localhost [sERVER_ADDR] => ::1 [sERVER_PORT] => 80 [REMOTE_ADDR] => ::1 [DOCUMENT_ROOT] => C:/xampp/htdocs [sERVER_ADMIN] => postmaster@localhost [sCRIPT_FILENAME] => C:/xampp/htdocs/larryullman/Sites/ecom_book/ex2/html/cart.php [REMOTE_PORT] => 50470 [GATEWAY_INTERFACE] => CGI/1.1 [sERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /larryullman/Sites/ecom_book/ex2/html/cart.php [sCRIPT_NAME] => /larryullman/Sites/ecom_book/ex2/html/cart.php [php_SELF] => /larryullman/Sites/ecom_book/ex2/html/cart.php [REQUEST_TIME] => 1355634766 ) [live] => [contact_email] => [uid] => 762d4f78b298d60a1d5279e67a5db64e [page_title] => Coffee - Your Shopping Cart [dbc] => mysqli Object ( [affected_rows] => -1 [client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $ [client_version] => 50008 [connect_errno] => 0 [connect_error] => [errno] => 1064 [error] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1 [field_count] => 0 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.16 [server_version] => 50516 [sqlstate] => 42000 [protocol_version] => 10 [thread_id] => 70 [warning_count] => 0 ) [r] => ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\larryullman\Sites\ecom_book\ex2\html\cart.php [line] => 117 [function] => mysqli_num_rows [args] => Array ( [0] => ) ) ) Your Shopping Cart Your shopping cart is currently empty.
  10. Yes, that's correct...It returns rows if the cart session_id is hardcoded in phpmyadmin but not with the variable.
  11. Well, here are my latest findings. The query below works in phpmyadmin when the user_session_id is used instead of the $uid variable:- SELECT CONCAT("O", ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, ncp.energy, ncp.protein, ncp.fat, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type="other" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="other" AND c.user_session_id="871a5d394995b479efd5a2e9bfce249c" After trying virtually every variation for the variable "$uid" such as ".$uid." the query run using phpmyadmin doesn't show any rows listed. I have noticed that the stored procedure get_shopping_cart_contents defines uid as a char so maybe it has to be defined either in the query or the code of cart.php.
  12. I think I had a similar problem but it was a long time ago. The query to most popular pages could be the source of the error. Try replacing this query with what you have in your code in index.php q = "SELECT COUNT(history.id) AS num, pages.id, pages.title FROM pages, history WHERE pages.id=history.page_id AND history.type='page' GROUP BY (history.page_id) ORDER BY num DESC LIMIT 10"; Cheers
  13. Here is the query with double quotes removed but still generates parse errors: $r = mysqli_query($dbc, 'SELECT CONCAT("O", ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, ncp.energy, ncp.protein, ncp.fat, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type="other" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="other" AND c.user_session_id="$uid" UNION SELECT CONCAT("C", sc.id), c.quantity, gc.category, CONCAT_WS(" - ", s.size), sc.price, sc.stock, sc.energy, sc.protein, sc.fat, sales.price FROM carts AS c INNER JOIN specific_coffees AS sc ON c.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id LEFT OUTER JOIN sales ON (sales.product_id=sc.id AND sales.product_type="coffee" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="coffee" AND c.user_session_id="$uid"'); I don't know why it works as a stored procedure but not as a non-procedural statement. Perhaps it's because of syntax errors! Cheers
  14. I think I know what to do now! The solution requires another procedure called call_select_sizes to show the various sizes in the pulldown list and another while loop withingin the existing cart.php loop. Two while loops could be impractical from a design perspective!
  15. I am now trying to develop a website that requires a dropdown select menu with a cart program based on the coffee cart. It has to display various sizes like the one in the admin section of add_other_products.php. Is it feasible or not given that add inventory for specific products has a while loop with bound variables and a server request method unlike cart.php and cart.html that has a form action validation method and relies on the database integration through a complex join? Here is is the select menu in add_other_products.php fyi. <div class="field"><label for="quantity"><strong>Quantity</strong></label><br /><select name="quantity"<?php if (array_key_exists('quantity', $add_product_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = 'SELECT id, size FROM sizes ORDER BY size ASC'; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['quantity']) && ($_POST['quantity'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?>
  16. I should have express myself more clearly but I did read "Rewriting the E-Commerce Stored Procedures with Standard PHP-MySQL #2, Chapter 9". Here is the link: http://www.larryullm...ql-2-chapter-9/ After putting the get_shopping_cart query from the above article in cart.php and removing the stored procedure call the program returns an error message in relation to "O", "C", "Other", and "Coffee". Once these double quotes are replaced with single quotes, Coffee works and says, "Your Shopping Cart is currently empty!" I then commented out the stored procedure and included the code from rewriting stored procedure chaper 9 in the above link. Nevertheless, the program produces an error message: "An error occurred in script 'C:\xampp\htdocs\larryullman\Sites\ecom_book\ex2\html\cart.php' on line 93: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array In other word no rows have been returned! Here is the exact query rewritten for a non-stored procedural evironment from the above article Rewriting stored procedures ch.9: $r = mysqli_query($dbc, "SELECT CONCAT("O", ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type='other'AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="other" AND c.user_session_id='$uid' UNION SELECT CONCAT("C", sc.id), c.quantity, gc.category, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole), sc.price, sc.stock, sales.price FROM carts AS c INNER JOIN specific_coffees AS sc ON c.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id LEFT OUTER JOIN sales ON (sales.product_id=sc.id AND sales.product_type='coffee' AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="coffee" AND c.user_session_id='$uid'"); Hopefully this explnation is more concise!
  17. The stored procedure from chapter 9 get_shopping_cart_contents does not appear to work in a non-stored procedure environment. It works as a stored procedure but not when the whole query is included in the code of the cart.php script. I done a search but I've not found anything. Here is the procedure that I have placed in the cart script: $r = mysqli_query($dbc, 'SELECT CONCAT("O", ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, ncp.energy, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type="other" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="other" AND c.user_session_id="$uid" UNION SELECT CONCAT("C", sc.id), c.quantity, gc.category, CONCAT_WS(" - ", s.size), sc.price, sc.stock, sc.energy, sales.price FROM carts AS c INNER JOIN specific_coffees AS sc ON c.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id LEFT OUTER JOIN sales ON (sales.product_id=sc.id AND sales.product_type="coffee" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="coffee" AND c.user_session_id="$uid"'); The error message states that no rows have been returned. Does anyone konw why? System Information: MYSQL 5.5.16, PHP Version 5.3.8, Windows NT, XAMPP 1.7.7
  18. Thank you for your suggestions. It gave inspiration to tackcle this enquiry with a new direction. I've also been able to partially use decimals by tracking the $qty variable with an echo command in the cart script and by changing the mysql database attributes from tinyint to decimals. I still have much to do especially with the way the info is obtained from the previous page but I think I can do it eventually. Cheers!
  19. Thanks for your response. If I alter the filter_validate_int to filter_validate_float and drop the extra parameters as with the following: //$qty = (filter_var($qty, FILTER_VALIDATE_FLOAT, array('min_range' => 0))) ? $qty : 1; $qty = (filter_var($qty, FILTER_VALIDATE_FLOAT)); the cart quantity continues to display an integer when updated. And even if the filter_validate_float line is not included then it still generates an interger. The reason I want to use decimals is that I intend to write a nutrition program that will use decimals for various quantities. For instance if define a given food serving size as 100 grams and then I have one and a half servings then that equals 1.5.
  20. I don't know how to modify the cart script to accommodate decimals in the $qty input field! Everytime I try to use say 1.3 and click on the update button the digit is rounded up or down. After changing the filter validation from INT to FLOAT I thought it would allow decimals but this is not the case! Does anyone know how I would go about inputing decimals in the cart quantity field? Here is cart.php: <?php // This file manages the shopping cart. // This script is begun in Chapter 9. // Require the configuration before any PHP code: require ('./includes/config.inc.php'); // Check for, or create, a user session: if (isset($_COOKIE['SESSION'])) { $uid = $_COOKIE['SESSION']; } else { $uid = md5(uniqid('biped',true)); } // Send the cookie: setcookie('SESSION', $uid, time()+(60*60*24*30)); // Include the header file: $page_title = 'Coffee - Your Shopping Cart'; include ('./includes/header.html'); // Require the database connection: require (MYSQL); // Need the utility functions: include ('./includes/product_functions.inc.php'); // If there's a SKU value in the URL, break it down into its parts: if (isset($_GET['sku'])) { list($sp_type, $pid) = parse_sku($_GET['sku']); } if (isset ($pid, $sp_type, $_GET['action']) && ($_GET['action'] == 'add') ) { // Add a new product to the cart: $r = mysqli_query($dbc, "CALL add_to_cart('$uid', '$sp_type', $pid, 1)"); // For debugging purposes: //if (!$r) echo mysqli_error($dbc); } elseif (isset ($sp_type, $pid, $_GET['action']) && ($_GET['action'] == 'remove') ) { // Remove it from the cart. $r = mysqli_query($dbc, "CALL remove_from_cart('$uid', '$sp_type', $pid)"); } elseif (isset ($sp_type, $pid, $_GET['action'], $_GET['qty']) && ($_GET['action'] == 'move') ) { // Move it to the cart. // Determine the quantity: $qty = (filter_var($_GET['qty'], FILTER_VALIDATE_INT, array('min_range' => 1))) ? $_GET['qty'] : 1; // Add it to the cart: $r = mysqli_query($dbc, "CALL add_to_cart('$uid', '$sp_type', $pid, $qty)"); // Remove it from the wish list: $r = mysqli_query($dbc, "CALL remove_from_wish_list('$uid', '$sp_type', $pid)"); } elseif (isset($_POST['quantity'])) { // Update quantities in the cart. // Loop through each item: foreach ($_POST['quantity'] as $sku => $qty) { // Parse the SKU: list($sp_type, $pid) = parse_sku($sku); if (isset($sp_type, $pid)) { // Determine the quantity: $qty = (filter_var($qty, FILTER_VALIDATE_FLOAT, array('min_range' => 0))) ? $qty : 1; // Update the quantity in the cart: $r = mysqli_query($dbc, "CALL update_cart('$uid', '$sp_type', $pid, $qty)"); } } // End of FOREACH loop. }// End of main IF. // Get the cart contents: $r = mysqli_query($dbc, "CALL get_shopping_cart_contents('$uid')"); //echo '<pre>' . print_r ($energy, 1) . '</pre>'; //echo '<pre>' . print_r ($r, 1) . '</pre>'; //print $energy; //print $r; if (mysqli_num_rows($r) > 0) { // Products to show! include ('./views/cart.html'); } else { // Empty cart! include ('./views/emptycart.html'); } // Finish the page: include ('./includes/footer.html'); ?> Cheers
  21. Good news! I've decided to hardcode the select menu for sizes into the non-coffee product script with a little success. One of the probs I face now is to transfer the size information to the cart menu. Here is the peace of the code I wrote in list_products.html to display the select dropdon menu containing sizes: echo ' <td align="center" width="2%"><select name="sku"> <OPTION VALUE=' . $row['sku'] . '>25</option>\n"; <OPTION VALUE=' . $row['sku'] . '>50</option>\n" <OPTION VALUE=' . $row['sku'] . '>75</option>\n" <OPTION VALUE=' . $row['sku'] . '>100</option>\n" </td>; <td align="center" width="26%"><p><a href="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/cart.php?sku=' . $row['sku'] . '&action=add" class="button">Add to Cart</a></p></td> I think I will need to probably store sizes infomation into the database?
  22. Here is the first part of the stored procedure select_products that retrieves coffee products from various categories. The only glich is that all the various sizes from the database do not display in a drop down list. Bugs do exist when info is transfered to cart such as categorie names appearing instead product names. but if I can can the dropdown displaying all the sizes then I can move onto the next thing. SELECT gc.description, gc.image, CONCAT("C", sc.id) AS sku, CONCAT_WS(" - ", s.id, s.size) AS coffee_name, sc.stock, sc.price FROM specific_coffees AS sc INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id WHERE general_coffee_id=cat The html code, tables and data appear in previous postings of the thread. Cheers!
  23. It's true that the existing specific_coffees page shows coffees by category and when you click on view kona coffee you get a drop down list with all the various products in it. This is probably why the data in my specific_coffees table has gc.id 3 showing only in 3 sizes and 4 is only in 2. My real intention is to create a specific products listing for all coffee products in a given category similar to the non-coffee products listing but with a drop-down listing every size from the sizes table. A user i.e., myself can then select a product from several rows of products on a page displaying, image, coffee_product, price, stock, a drop down displaying every size and an add to cart button. Here is the php and html coding with my changes to list_coffees2.html but please disgread any minor variations from the original coding as I am trying to write a food dietary program with different cattegories of vegetables etc: <?php // This page is included by browse.php. // This page displays the available coffee products. // This page will make use of the query result $r. // The query returns an array of: description, image, sku, name, and stock. echo '<table border="0" width="100%" cellspacing="1" cellpadding="4"> <tr> <th align="center">Image</th> <th align="center">Coffee_Name</th> <th align="center">Price</th> <th align="center">Stock</th> <th align="center">Size</th> <th align="center">Cart</th> </tr> '; // Only display the header once: $header = false; // Added later in Chapter 8: include ('./includes/product_functions.inc.php'); // Loop through the results: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { // If the header hasn't been shown, create it: if (!$header) { ?> <!-- box begin --> <h2><?php echo $category; ?></h2> < <p><img alt="<?php echo $category; ?>" src="[url="http://localhost/Sites/ecom_book/ex2.2/html/products/http://localhost/Sites/ecom_book/ex2.2/html/products/%20echo%20$row['image'];%20?>"] <?php echo $row['description']; ?></p> <p><small>All listed products are currently available.</small> <?php // The header has now been shown:[/url] [url="http://localhost/Sites/ecom_book/ex2.2/html/products/http://localhost/Sites/ecom_book/ex2.2/html/products/%20echo%20$row['image'];%20?>"] $header = true; } // End of $header IF.[/url] [url="http://localhost/Sites/ecom_book/ex2.2/html/products/http://localhost/Sites/ecom_book/ex2.2/html/products/%20echo%20$row['image'];%20?>"] [/url] [url="http://localhost/Sites/ecom_book/ex2.2/html/products/http://localhost/Sites/ecom_book/ex2.2/html/products/%20echo%20$row['image'];%20?>"] ?> <tr> <td width="21%"><div class="img-box"><p><img alt="<? echo $row['name']; ?>" src="[/url] [url="http://localhost/Sites/ecom_book/ex2.2/html/products/"]http://localhost//Sites/ecom_book/ex2.2/html/products/[/url]<? echo $row['image']; ?>" /> </p></td> <td align="center" width="6%" ><? echo $row['coffee_name']; ?></td> <td align="center" width="6%" ><? echo $row['price']; ?></td> <td align="center" width="6%" ><? echo $row['stock']; ?></td> <input type="hidden" name="action" value="add" /> <td align="center" width="6%" ><select name="sku"><option value="0">choose</option><?php echo "<option value=\"{$row['sku']}\">{$row['coffee_size']}</option>\n"; ?></td>; <td align="center" width="6%" ><form action="[url="http://localhost/Sites/ecom_book/ex2.2/html/cart.php"]http://localhost/Sites/ecom_book/ex2.2/html/cart.php[/url]" method="get"> <td align="center" width="7%" height="10"><input type="submit" value="Add to Cart" class="button" /></p></td></form> </select></tr> <?php } // End of WHILE loop.} ?> </tbody></table>
  24. Yes, I thought the inner join on the sizes table could be the reason why me new sizes table does not completely display the five various sizes in the drop-down list. I've already tried LEFT or RIGHT OUTER JOIN to no avail. The specific_coffees table listed beiow shows the data for testing purposes. A foreign key-primary key relation exists I believe between s.id and sc.size_id. Id general_coffe_id size_id coffeename image price stock date_created 3 3 4 defcaf - 50.00 10 2012-09-19 1 4 5 instant - 15.00 90 2012-09-19 4 3 5 blend_43 - 22.00 4 2012-09-19 2 4 3 dark_coffee - 70.00 10 2012-09-19 14 3 4 ground_whole - 12.00 10 2012-10-10 Here is the sizes table: id size 1 25 grams 2 50 grams 3 75 grams. 4 100 grams 5 1.25 grams Hope this explanation clarifies things.
×
×
  • Create New...