Jump to content

Ecommerce Product Page Help


phantom552

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by phantom552
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.