SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Slovenia
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Generate html from MySql using templates?

    What is the best way to generate static HTML files from MySql database using html templates with some specific tags like [tag].
    So for example: in MySql i have a database = database and table = table. In this table i have some columns and data like:
    name | surname | telephone | address | city | country |
    ------------------------------------------------------
    John | Smith |12345678 | adress1 | Kranj | Slovenia |
    ........

    Then I have a HTML template (template.htm) which look like this:
    <html>
    <head>
    <title> [name] [surname] </title>
    </head>
    <body>
    [name] <br>
    [surname] <br>
    [telephone] <br>
    [address] <br>
    ....
    </body> </html>

    Now I do this:
    - read template.htm into $contents
    - replace all tags like [name], [surname] ... with columns from database
    ( str_replace ("[name]", $row[name], $contents) etc )
    - create a directory $row[name]
    - write $contents into new file (name/index.htm)
    - loop until end of entries in database

    It works fine, but I am wondering if there is any other way to do that. Any suggestions?

    I know that I can use a PHP file and call everything from database but I need to generate static html files.

  2. #2
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm no XML expert but I believe you may be able to do something like this with XML, I know PHP has some XML functions. However I have little experience with it. You can check here http://ca2.php.net/manual/en/ref.xml.php or just search the forum for XML parser.

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Or you could try using the adoDB database object. It has a method that'll create the HTML for you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •