skim5_1999 Posted May 5, 2011 Share Posted May 5, 2011 Hello, In Example 2 home page, when you click ont he red mug, it takes you to a sales page with the red mug on top PLUS all these other products. I am in the process of creating my own Dynamic catalogue and would like to learn if there's a way to click on that red mug on the home page and then land on a sales page that ONLY has details of the red mug, and no other products. More specifically, the current codes on Ex 2 is as follow: 1) The red mug on the home page has the following href: <a href="/shop/sales/#' . $row['sku'] .'> 2) The above ultimately goes to a list_sales.html page with the following codes: "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="/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="/cart.php?sku=' . $row['sku'] . '&action=add" class="button">Add to Cart</a></p></div>';" 3) Is there a way to still link the home page to the list_sales.html but so that only one "SKU" or product is shown at a time? I already tried taking out the "while" loop but then it just shows the very first row even if other products are selected on the home page. I basically want so that a pix of the product the consumer selects from the home page takes them to a detailed page about that one product in a dynamic fashion... THANK YOU! sjk Link to comment Share on other sites More sharing options...
Larry Posted May 6, 2011 Share Posted May 6, 2011 I would create a "product" page that lists a single product. That page should be passed the SKU. Then you change the link so it goes to the product page. Link to comment Share on other sites More sharing options...
skim5_1999 Posted May 7, 2011 Author Share Posted May 7, 2011 Hello - Thanks for your reply. I'm quite a newbie, I actually have trouble figuring out how to "pass the SKU" over to a specific page. Is there a mysqli function that passes it over so it "catches" and recognizes just one SKU? the mysqli_fetch either gives me all the SKU or just the first one...Thanks so much! This book has really helped me get my business started Sjk Link to comment Share on other sites More sharing options...
Jonathon Posted May 7, 2011 Share Posted May 7, 2011 Hi, The book has some quite complex code in it, so if you are new to PHP you may struggle to adapt your code to meet your needs. I have read Larry's "PHP and MYSQL" which is a good primer for the effortless e-commerce book. There is also "PHP for the Web" which may be a good option for you too, however I haven't read it. In answer to your question: To a pass over the SKU there are a couple of ways. I suspect that the $_GET['var'] will suffice. To use this you need to have a set up similar to this: page.php <?php echo '<a href="product.php?sku=15">See Product 15</a>'; ?> then on product.php <?php if(isset($_GET['sku'])) { $sku = $_GET['sku']; } else { // default page if no sku or invalid } ?> From there you can use the $sku variable you created in your mysqli queries Hope that helps 1 Link to comment Share on other sites More sharing options...
skim5_1999 Posted May 14, 2011 Author Share Posted May 14, 2011 Thank you so much, Jonathon, again! It took me a long time, but thanks to your initial guidance, i finally figured out what I have to do to make it more dynamic and not have every single item shown with mysqli_fetchy_array. I'm sure there's some rookie mistake I'm making here, but here's what I've done for others who are looking to do the same thing On page.php, write "<?php echo '<a href="product.php?sku='.row['sku'].'">See Product 15</a>'; ?>" And then on product.php, write (after including the config and requiring MYSQL), "if (isset($_GET['SKU'])) { $sql="SELECT * FROM table WHERE table_id=".$_GET['SKU']; $result=mysqli_query ($dbc, $sql); $row=mysqli_fetch_array($result); echo ' <p> ' .$row['put a column name in the table here'] . ' </p> '; } yay! thanks! sjk Link to comment Share on other sites More sharing options...
Jonathon Posted May 15, 2011 Share Posted May 15, 2011 Yeah essentially that's it. You can always validate the $_GET['sku'] checking it's an integer maybe? so if(isset($_GET['sku']) && is_numeric($_GET['sku'])) { // Do something } also do you need to SELECT everything from the database? You can just: SELECT column, column2 FROM table WHERE sku=$_GET['sku'] But yeah well done 1 Link to comment Share on other sites More sharing options...
Recommended Posts