phantom552 Posted October 28, 2012 Share Posted October 28, 2012 So I set up my "Ecommerce" site (ecommerce being used loosely since it's technically more of an affiliate site), got the home page done, and used a PHP mysql query to build out the category pages (yay for echo "<div>" and CSS + PHP/mySQL). My question now is how do I go about adding single product pages without having to create each one individually? Each product has a unique ID in the DB table, is it possible to dynamically generate a link such as mysite.com/products.php?PRODUCTID then have that actually lead to a page populated with the table row data for that product? If so, how would I go about doing that? Will search engines still index a page generated in this fashion? Thank you for your help, I just started in on PHP programming this morning, so you could call me a novice for sure! Quote Link to comment https://forums.phpfreaks.com/topic/270001-ecommerce-product-page-help/ Share on other sites More sharing options...
gizmola Posted October 28, 2012 Share Posted October 28, 2012 Yes, that is the way most websites of any competency work. You have a variety of scripts (or controllers in mvc) that tend to do one thing, or several things based on the paramters that are sent to them. In your case, probably the easiest path is to write a script that displays the single page, exactly as you showed in your example: mysite.com/products.php?id=3 And in that script you'd get the value from the $_GET superglobal $id = (int)$_GET['id']; if ($id >0) { // do your database lookup by ID, and display the information } As for having a search friendly url, yes you could use mod_rewrite to setup a rewrite rule, so that the url's you present, and accept are actually in the form of: mysite.com/products/44 A typical rewrite rule would look like this: Options +FollowSymLinks RewriteEngine On RewriteRule ^products/([0-9]+)$ products.php?id=$1 There are scores of tutorials around on creating a simple mod rewrite rule that will configure your apache site by adding the rewrite rule to the .htaccess file of your root directory. Keep in mind that anyplace you render a link to your own products, you must render the /mysite.com/products/44. People are often confused about how rewrites work. They work on people who are trying to access your site, and don't translate the links you output in your scripts on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/270001-ecommerce-product-page-help/#findComment-1388287 Share on other sites More sharing options...
phantom552 Posted October 28, 2012 Author Share Posted October 28, 2012 (edited) Thanks for the input, I am familliar with the mod rewrite rule & plan to use it once I get the base functionality set up, more just looking for basically how to A) generate a page that has the PID appended to the URL, then strip the PID back out of the url to store it as a variable for use in a query, which it looks like you showed me in the first half of your response. Thank you again! lol. Most of the time I know what I want in my head and just can't think of how to make it appear in the scripting >.< Edited October 28, 2012 by phantom552 Quote Link to comment https://forums.phpfreaks.com/topic/270001-ecommerce-product-page-help/#findComment-1388289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.