php - creating individual html pages for each output of a WHILE statement

Associate
Joined
24 Jul 2004
Posts
1,580
Location
Preston, Lancs
Hi,

I have a WHILE statement that runs through my database query and outputs each record to the screen. All the records display on the same page.

I would like to somehow create a new page at the start of each loop using the $title variable from my query, run through the loop and write all that data to the page, then close that page and create a new one and repeat.

I have my while loop written but im unsure how to go about putting the contents of each loop into their own page.

Any help appreciated
 
am i being thick, or are you actually trying to create files from your database output? can't you just view the content dynamically, and call each database entry as-and-when requested from a sitemap or something?
 
yeah sorry it would be creation of a new file for each database record, rather than viewing them dynamically. I have had a few more ideas on this but thanks for the input.
 
It should be as simple as running an fwrite() or file_put_contents() [PHP5] on each iteration of your while loop. Something akin to:

Code:
while ($r = mysql_fetch_assoc($result)) {
   $output = $r['foo'];
   $output .= 'something else';
   file_put_contents("$title.txt", $output);
}
Or you could use a templating engine like Smarty, assign the variables to the template and capture the output on each iteration.
 
Back
Top Bottom