| | #1 |
| HyperActive Warrior Join Date: 2010
Posts: 105
Thanks: 0
Thanked 3 Times in 2 Posts
|
I have a section on my site in every page that has 'recent posts' and have just realised that i may have to update my static html pages to change the recent posts as with blogger or word press it changes automatically. Is there anyway i can add code so that it updates automatically? |
| |
| | #2 |
| HyperActive Warrior Join Date: 2011
Posts: 198
Thanks: 3
Thanked 19 Times in 19 Posts
|
You can update such pages with code similar to this: <?php $data = "This message will be printed into printed.txt file"; $file= fopen("printed.txt", "w"); fwrite($file, $data); fclose($file); $file2= fopen("printed2.txt", "w"); fwrite($file2, $data); fclose($file2); echo "Printed.txt updated!"; echo "<br>"; echo "Printed2.txt updated!"; ?> The print.txt file will need to have write permissions 0777. You simply include the altered file into whatever page you need using php include or similar. The $data can be put inside a while loop even and it will work from there - similar to this: <?php // Database connection require('../config.php'); $result = mysql_query("select query here") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { $data .= "" . $row['row name here'] . "\r\n"; } ; $file= fopen("printed.txt", "w"); fwrite($file, $data); fclose($file); $file2= fopen("printed2.txt", "w"); fwrite($file2, $data); fclose($file2); echo "Printed.txt updated!"; echo "<br>"; echo "Printed2.txt updated!"; ?> |
| |
|
| Bookmarks |
| Tags |
| html, pages, posts, problem, recent, static |
| |