phphtmlmysqlajax

How to use PHP and MySQL to display different items with only one web page


My e-business web site is actually a search engine.

Step 1 : users can search the item they like by key words or other attributes.

Step 2: After that, user may find the items they like, and click on the title of a specific item (or picture,etc) to activate a hyperlink.

Step 3: Then a web page that describes the detail of the item will appear.

I was stuck in Step 3.

I found that there are more than 10 thousand items in MySQL database. I wondered if I need to create more than 10 thousand webpages to describe the details for each items ?(Of course it is impractical, but I don't know how to build only one web page to solve this problem).

p.s. An idea has once come into my mind that I can build a share web page for describing the detail of items, and find a way to detect which hyperlink or item user have clicked on, but I haven't learn this skill. Is it possible, or is there a better way?


Solution

  • You need like 3 pages:

    1. index.php
    2. results.php
    3. detail.php

    In detail.php, you'll need to build a query to get the appropriate information about the item.

    You could create for each result a unique link, by adding its id to the url:

    detail.php?id=23 // for example
    

    Then on the detail page, you can catch the id like this, and query the database to get all the information about that product:

    // Get the product id
    product_id = isset($_GET['id']) ? $_GET['id'] : false;
    
    // Check if product id is set
    if ($product_id) :
        // Query the database and make a template to display your product info here
    endif;
    

    This should give you an idea on how to do it basicly.