How do you create a unique page for each item in a database?

Discussion in 'Programming' started by yonghoshin, Jan 8, 2009.

  1. #1
    I have a large database of items, and each has a unique ID. I would like to achieve the following:

    If a user wants to find out information on item 3563, he can do so by accessing the URL http://domain.com/item/3563/.

    If he wants to find information on item 3565, he can do so by accessing http://domain.com/item/3565/.

    How can I achieve this? (If it helps, I would like to have something similar to how WordPress displays posts [it finds the entry in the database and shows it, even though there is no actual file with the name as the URL])
     
    yonghoshin, Jan 8, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    build a page with a $_GET parameter then do a mod_rewrite for
    in the page make a query like
    select * from tblName where id = '".mysql_real_escape_string(addslashes($_GET['id'])."'
     
    crivion, Jan 9, 2009 IP
  3. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #3
    .htaccess the way to achieve this.

    Other details are correctly mentioned by crivion.
     
    harrisunderwork, Jan 9, 2009 IP
  4. yonghoshin

    yonghoshin Peon

    Messages:
    70
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yonghoshin, Jan 10, 2009 IP
  5. JosephineX

    JosephineX Peon

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Pseudo rewrite code:

    
    "^/item/([0-9]+)/" => "item.php?id=$1"
    
    Code (markup):
    item.php file:

    
    // require_once('dbconnector.php');
    // connect();
    
    $id = $_GET[id];
    
    if(!is_numeric($id))
    {
    die('invalid id');
    }
    
    $select = mysql_query("SELECT * FROM table WHERE id = '$id' LIMIT 1");
    while($row = mysql_fetch_assoc($select))
    {
    //process all in here ($row[table_row_name])
    }
    
    PHP:
    I hope this helps.
     
    JosephineX, Jan 11, 2009 IP