1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to create dynamic HTML?

Discussion in 'PHP' started by flagday, Jul 28, 2008.

  1. #1
    Any guidance here would be greatly appreciated.

    I have a MYSQL db table that has everything I want for all of my pages:
    record1: page1.html ; title1 ; meta1 ; bodycontent1
    record2: page2.html ; title2 ; meta2 ; bodycontent2
    record3: page3.html ; title3 ; meta3 ; bodycontent3

    and so on and so forth.

    Now, how can I generate all of these pages from a single index.html?

    I can access the DB and fetch an array to list all of the titles, then assign a variable to all of the pages, so I come up with something like this on index.html:
    
    <a href="page1.html">title1</a>
    <a href="page2.html">title2</a>
    <a href="page3.html">title3</a>
    Code (markup):
    And all of those links work, except that there's no such page as page1.html yet, so I obviously get a 404.

    So, what do I need to do to get php to generate an html page using the other fields from the record it's currently on? Do I do this in the array itself? Is there a function I'm missing here?

    Hope that makes sense.

    Thanks
     
    flagday, Jul 28, 2008 IP
  2. pratibha01

    pratibha01 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    using style sheet u can create dynamic pages.:D:D
     
    pratibha01, Jul 28, 2008 IP
  3. flagday

    flagday Peon

    Messages:
    348
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    CSS? I thought that was just for layout/making it look pretty.:confused:

    Got a link?

    Guess not.
     
    flagday, Jul 28, 2008 IP
  4. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Uh, no CSS will not create Dynamic content...

    PHP will, and since you've already got the MySQL setup, I would do something along the lines of:

    
    $page = $str_replace(".html", "", $_SERVER['FILENAME']);
    $query = mysql_fetch_array(mysql_query("SELECT * FROM table WHERE page='$page' LIMIT 1"));
    extract($query, EXTR_PREFIX_ALL, "page");
    
    PHP:
    Forgive me if the code above has an error in it, it's a "rough draft" and I'm very tired at the moment, but it should give you an idea of how to go about making it work. (if you don't know what extract does, check this page: http://us.php.net/manual/en/function.extract.php )

    Good luck, and if I did make an error, please let me know and I'll fix it up tomorrow when I've had a full night's sleep and my brain works. :p
     
    Cri2T, Jul 28, 2008 IP
  5. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If page1.html / page2.html / page3.html don't exist then, if I what I understand you want to do is correct, you first need to redirect these to index.php and then handle the page request.

    To redirect you will have to use mod_rewrite in a .htaccess file:

    then the php code would be something like:


    or, do you want to get php to create static pages from the DB ?
     
    mallorcahp, Jul 29, 2008 IP
  6. cakung

    cakung Peon

    Messages:
    113
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yes...alright.you must create .htacces and then page.html will direct to your php file. :d thanks
     
    cakung, Jul 29, 2008 IP