HELP - automatically create file for each product in database

Discussion in 'PHP' started by snappingpig, Dec 20, 2007.

  1. #1
    I have a list of 376 products in my database (with prices, descriptions, ect) and I was wondering how to have these pages automatically get created. Example would be: product1.php, product2.php, ..... product376.php.

    Thanks
     
    snappingpig, Dec 20, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    That's not really a good practice, since you have the data in the database. You should create one dynamic page, which pulls the the based on a unique identifier, passed in the URL. Like: page.php?productid=3.
     
    nico_swd, Dec 20, 2007 IP
  3. snappingpig

    snappingpig Banned

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can you provide a simple setup code of a page like this? I am new to PHP.
     
    snappingpig, Dec 20, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    <?php
    
    // Make sure a database connection has been established at this point.
    
    $query = mysql_query("
        SELECT *
        FROM table_name
        WHERE productid = " . intval($_GET['id']) . "
        LIMIT 1
    ") OR die(mysql_error());
    
    if (!$product = mysql_fetch_assoc($query))
    {
        exit('Product not found.');
    }
    
    echo $product['product_name'];
    echo $product['price'];
    // etc
    
    ?>
    
    PHP:
    This should get you started. You have to open the page like: page.php?id=4.
     
    nico_swd, Dec 20, 2007 IP
    snappingpig likes this.
  5. snappingpig

    snappingpig Banned

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Awesome, I will play with this for awhile. I'll probably come back on the forums later for a few other questions.

    I gave you rep.

    Thanks!
    Best
     
    snappingpig, Dec 20, 2007 IP
  6. Paintball Guns

    Paintball Guns Active Member

    Messages:
    173
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Thanks for the great sample script. Is there a downloadable script template like this with SEO friendly URLs?

    I'm new to PHP and would like to create a dynamic website like this, but with SEO friendly URLs (using Apache or otherwise) and possibly some other features. Rather than try to modify this script, I wondered if there is a more robust script available somewhere, preferably free and with instructions.

    I've searched the web for "free php dynamic website script," "free php dynamic website builder," and related terms. These searches presented a few options:
    But I wondered what an experienced coder would recommend. BTW, I considered using Wordpress or Drupal, but those are far too complex for my needs. Maybe something like cakephp.org provides this.

    Any suggestions?
     
    Paintball Guns, Jan 2, 2008 IP