Jump to content
Larry Ullman's Book Forums

xto

Members
  • Content Count

    13
  • Joined

  • Last visited

  • Days Won

    1

xto last won the day on May 2 2013

xto had the most liked content!

Community Reputation

2 Neutral

About xto

  • Rank
    Newbie
  1. Hi All, sorry for being away for a while, just came back. Marg! Thanks. It is working now. However, I tried working on the pagination stuff following Larry's book on page Ch10, pg 316 but it is giving me " Commands out of sync; you can't run this command now." Here is my modified code. <?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. // This is the second version of the script, which handles the product's avaialability in a better manner.// Only display the header once: $header = false; // Added later in Chapter 8: include ('./includes/product_functions.inc.php');$display = 2; // Determine how many pages there are... if (isset($_GET['p']) && is_numeric ($_GET['p'])) { // Already been determined.$pages = $_GET['p']; }else { // Need to determine. // Count the number of records: $q = "SELECT COUNT(id) FROM non_coffee_products"; $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 of p IF.// Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric ($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } //Define the query: $q = "SELECT id, name, image, description, price AS id, name, image, description FROM non_coffee_products ORDER BY price ASC LIMIT $start, $display";//Run the query $r = @mysqli_query ($dbc, $q); $location = 1; $num_per_row = 3; echo '<table>'; echo '<tr>'; // Loop through the results: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {if ($location == $num_per_row) { // Close the previous row, start a new one, reset the counter: echo '</tr><tr>'; $location = 1; } // If the header hasn't been shown, create it: if (!$header) { ?> <!-- 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><?php echo $category; ?></h2> <p><img alt="<?php echo $category; ?>" src="/ecom/html/products/<?php echo $row['g_image']; ?>" /><br><?php echo $row['g_description']; ?></br></p> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"></div> </div> </div> </div> <!-- box end --><?php // The header has now been shown: $header = true; } // End of $header IF. // Show each product: echo '<td><h3>' . $row['name'] . '</h3> <p><img alt="' . $row['name'] . '" src="/ecom/html/products/' . $row['image'] . '" />'.'<br>' . $row['description'] . '<br /> <strong>Price:</strong> ₦' . $row['price'] . '<br /> <strong>Availability:</strong> ' . get_stock_status($row['stock']) . '</p> <p><a href="/cart.php?sku=' . $row['sku'] . '&action=add" class="button">Add to Cart</a></p></td>'; // Increment the counter: $location++; } // Complete the last row with empty cells, just in case: for ( ; $location < $num_per_row; $location++) { echo '<td> </td>'; } // End of WHILE loop. echo '</table>';mysqli_free_result ($r); mysqli_close($dbc); // Make the links to other pages, if necessary. if ($pages > 1) {// Add some spacing and start a paragraph: echo '<br /><p>'; // Determine what page the script is on: $current_page = ($start/$display) + 1;// If it's not the first page, make a Previous link: if ($current_page != 1) { echo '<a href="browse.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="browse.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; }} // End of FOR loop. // If it's not the last page, make a Next button: if ($current_page != $pages) { echo '<a href="browse.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; }echo '</p>'; // Close the paragraph. } // End of links section.?>
  2. Thank Hartley, Will get one asap. I need to start from the basic -> HTML, CSS, PHP and MySQL. Hope I'm correct. Cheers
  3. Hi Marg thanks. I have to be frank here. I am studying PHP and MySQL for Dynamics website (Fourth Edition) now after I got recommendation from Effortless E-Commerce with PHP and My SQL to see if I can write PHP codes. I also have expert PHP and MySQL by Andrew Curiso et al. I have not started learning HTML. Is it the basics for learning PHP and MySQL? Kindly recommend a nice book on it for me. I don't like confusing myself with many books on same subject. These two Larry's book is OK for a beginner like me on PHP and MySQL. I just wanted to tweak some things I see in other websites and get grounded on it. If you wouldn't mind, I want to display 24 items in each category in a 8 x 3 matrix , i.e. it will have 8 rows and 3 columns. If it exceeds 24 items let say 50 items, then the remaining will be displayed in other pages. I know I have to change stuffs in browse.php. sales.php, shop.php and some html files. I will do all it takes to learn this. Just tell me what to do. I'm grasping this PHP stuff by Larry anyway. It is helpful for beginners like me. Thanks Thanks
  4. Hi Larry, thanks for the reply. I inserted six items to the category to see if it will display as 2 X 3 matrix but I still have it as one column. Please, any idea on what I'm not doing right, I have not included the pagination yet.It is not giving me any error. Here is my code: <?php $location = 1; $num_per_row = 3; echo '<table>'; echo '<tr>'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { // Fetch each item. if ($location == $num_per_row) { // Close the previous row, start a new one, reset the counter: echo '</tr><tr>'; $location = 1; } // Print the item within some HTML: echo '<li><h3>' . $row['category'] . ' </h3> <p><img alt="' . $row['category'] . '" src="/products/' . $row['image'] . '" />' . $row['description'] . '<br /> <a href="/browse/' . $type . '/' . urlencode($row['category']) . '/' . $row['id'] . '" class="h4">View All ' . $row['category'] . ' Products</a></p> </li>'; // Increment the counter: $location++; } // Complete the last row with empty cells, just in case: for ( $location < $num_per_row; $location++) { echo '<td> </td>'; } } ?>
  5. Hi All, How do I view items in a product category in 3 x 3 rows&column. Any explanatory code will be valued.
  6. Hmmmm! Sigh of relief at last. It's time to dig into the gold (PHP AND MYSQL FOR DYNAMIC WEBSITE). Larry, thanks for putting these stuffs in a book. Aside my men, Marg,Antonio et al, thanks for helping me dig deeper. See me in another tread soon. End Of Discussion (EOD) for this tread. Cheers
  7. Hi my men! please, I tried following the book steps in fixing the superfish and hoverintent. I downloaded the files and put the two .js files in js folder and the CSS file in the CSS folder. I also modified the path as I did for others, however, I can't click on the drop down menu to access it. Please, any clue on how to fix this will be appreciated. Thanks
  8. Thanks for the little bashing to be frank I never read the forum rules; didn't know one exists, was focused find answers to my problems. I assure you I will read it and follow up. Will try your suggestion and then read the forums guide lines. Thanks and cheers
  9. Margaux and Antonio, thanks a load. Your assistance helped me a lot. I have fixed the problem. But I have another one, don't be annoyed please. I downloaded the superfish.js and hoverintent.js and when I try to move my mouse to click on add_specific_coffee it disappears immediately. My mouse can't reach it at all. I did everything in the book but it's not working man. I also have an undefined index sales_price in list_products3.html that is linked to browse.php. please assist in the best way forward. Thanks Find error below: An error occurred in script 'C:\xampp\htdocs\ecom\html\views\list_products3.html' on line 60: Undefined index: sale_price Array ( [0] => Array ( [file] => C:\xampp\htdocs\ecom\html\views\list_products3.html [line] => 60 [function] => my_error_handler [args] => Array ( [0] => 8 [1] => Undefined index: sale_price [2] => C:\xampp\htdocs\ecom\html\views\list_products3.html [3] => 60 [4] => Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( [type] => goodies [category] => Mugs [id] => 3 ) [_COOKIE] => Array ( [sESSION] => db6f802f760980b5bb4fe7d9d480be29 [phpSESSID] => db6f802f760980b5bb4fe7d9d480be29 ) [_FILES] => Array ( ) [live] => [contact_email] => you@example.com [category] => Mugs [sp_cat] => 3 [sp_type] => other [type] => goodies [page_title] => Goodies to Buy::Mugs [dbc] => mysqli Object ( [affected_rows] => 2 [client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $ [client_version] => 50008 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [field_count] => 8 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.16 [server_version] => 50516 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 932 [warning_count] => 0 ) [r] => mysqli_result Object ( [current_field] => 0 [field_count] => 8 [lengths] => Array ( [0] => 91 [1] => 19 [2] => 2 [3] => 14 [4] => 93 [5] => 44 [6] => 4 [7] => 2 ) [num_rows] => 2 [type] => 0 ) [header] => 1 [row] => Array ( [g_description] => A selection of lovely mugs for enjoying your coffee, tea, hot cocoa or other hot beverages. [g_image] => 781426_32573620.jpg [sku] => O2 [name] => Red Dragon Mug [description] => An elaborate, painted gold dragon on a red background. With partially detached, fancy handle. [image] => 847a1a3bef0fb5c2f2299b06dd63669000f5c6c4.jpg [price] => 7.95 [stock] => 22 ) ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\ecom\html\browse.php [line] => 61 [args] => Array ( [0] => C:\xampp\htdocs\ecom\html\views\list_products3.html ) [function] => include ) )
  10. Thanks a load my man! Your insight help me a lot. I managed to pinpoint the error. The base URI was pointing to the database for knowledge is power (commerce1). I have change it. However, I have a little problem, the site images are not loading. I know this is a minor error you can help me fix. You can't imagine how happy I am. you have made my day.
  11. Hi Larry et al, I have checked the database and found out that I have executed this command and it showed executed. I have got no expert knowledge to solve it cause I'm a newbie. Please assist. Command: " DELIMITER $$ CREATE PROCEDURE select_sale_items (get_all BOOLEAN) BEGIN IF get_all = 1 THEN SELECT CONCAT("O", ncp.id) AS sku, sa.price AS sale_price, ncc.category, ncp.image, ncp.name, ncp.price, ncp.stock, ncp.description FROM sales AS sa INNER JOIN non_coffee_products AS ncp ON sa.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id WHERE sa.product_type="other" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) UNION SELECT CONCAT("C", sc.id), sa.price, gc.category, gc.image, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole), sc.price, sc.stock, gc.description FROM sales AS sa INNER JOIN specific_coffees AS sc ON sa.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 WHERE sa.product_type="coffee" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ); ELSE (SELECT CONCAT("O", ncp.id) AS sku, sa.price AS sale_price, ncc.category, ncp.image, ncp.name FROM sales AS sa INNER JOIN non_coffee_products AS ncp ON sa.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id WHERE sa.product_type="other" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) ORDER BY RAND() LIMIT 2) UNION (SELECT CONCAT("C", sc.id), sa.price, gc.category, gc.image, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole) FROM sales AS sa INNER JOIN specific_coffees AS sc ON sa.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 WHERE sa.product_type="coffee" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) ORDER BY RAND() LIMIT 2); END IF; END$$ DELIMITER ; " .
  12. @Larry, thanks. @ HartleySan I work hard to make people laugh I.'m also amused. Thanks and cheers .
  13. Hi All, I'm a newbie in PHP/MySQL and this place has been helpful, Larry thanks. My coffee site is not coming up while knowledge is power is up and firing. I was very happy until my coffee site refuses to come up. This is the error message I'm getting: An error occurred in script 'C:\xampp\htdocs\ecom\html\views\home.html' on line 14: 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\ecom\html\views\home.html [3] => 14 [4] => Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( [phpSESSID] => 30nvl7ovcsvt9lgskus5jacdq6 ) [_FILES] => Array ( ) [live] => [contact_email] => you@example.com [page_title] => Coffee - Wouldn't You Love a Cup Right Now? [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] => 1305 [error] => PROCEDURE ecommerce1.select_sale_items does not exist [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] => 406 [warning_count] => 0 ) [r] => ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\ecom\html\views\home.html [line] => 14 [function] => mysqli_num_rows [args] => Array ( [0] => ) ) [2] => Array ( [file] => C:\xampp\htdocs\ecom\html\index.php [line] => 20 [args] => Array ( [0] => C:\xampp\htdocs\ecom\html\views\home.html ) [function] => include ) ) Please what am I doing wrong. I didn't change anything except my URI. Thanks for rescuing me in advance.
×
×
  • Create New...