Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 7th May 2011, 03:38 AM   #1
HyperActive Warrior
 
Join Date: 2010
Posts: 105
Thanks: 0
Thanked 3 Times in 2 Posts
Default
Recent posts on static html pages problem?
Share on: 
fb share twitter share gplus share more share

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?
skyvia is offline  
Unread 7th May 2011, 04:09 AM   #2
Mkj
HyperActive Warrior
 
Join Date: 2011
Posts: 198
Thanks: 3
Thanked 19 Times in 19 Posts
Default
Re: Recent posts on static html pages problem?
Share on: 
fb share twitter share gplus share more share

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!";

?>
Mkj is offline  
Closed Thread


Bookmarks

Tags
html, pages, posts, problem, recent, static


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 06:29 AM.