Solution for creating static files out of MySQL?

Discussion in 'Programming' started by Domen Lombergar, May 30, 2008.

  1. #1
    Hi guys.

    I'm looking for a solution to merge a MySQL database with a static file (for example put everything into HTML files)

    So for example if i have 1000 entries it would use a template i give it and create 1000 files.

    Is there anything like this available?

    Thanks.
     
    Domen Lombergar, May 30, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    $result = mysql_query("SELECT * FROM `pages`;");
    while($db=mysql_fetch_assoc($result)){
    $filename = "pages/" . $db['title'] . ".html";
    $fileHandle = fopen($filename ,"w");
    fwrite($fileHandle, $db['content']);
    fclose($fileHandle);
    }
    
    Code (markup):
    This is assuming that, for example, you are using a table called "pages" with a "title" field and a "content" field. It will make the title the filename, and the content the content of the file. It will create these files in the /pages/ directory.
     
    crath, May 30, 2008 IP
    Domen Lombergar likes this.
  3. Domen Lombergar

    Domen Lombergar Peon

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I understand the code, but it wouldn't help me in the fact that i would need to "merge" this with a predefined template.

    ...

    Now that i look at your code it looks extremely simple to include two more files or one and explode it at some character so you'd get a header and a footer too.

    Thanks so much for the help!
     
    Domen Lombergar, May 30, 2008 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    no prob, +rep please :)
     
    crath, May 30, 2008 IP
  5. Domen Lombergar

    Domen Lombergar Peon

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Done, have a great one :)
     
    Domen Lombergar, May 30, 2008 IP