MetroidMaster1914 Posted June 14, 2007 Share Posted June 14, 2007 I'm making an update system where the site admin writes a new update to a file in the archives which contain only the HTML of the update, not the whole page. Then what I want to happen is for the main index.php file to display the latest 5 updates from the archive directory. I'm not sure how to make that happen. Any and all help in this area would be very much appreciated. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 14, 2007 Share Posted June 14, 2007 Just create a table called "updates" with these fields: updateID poster (person who posted update) date_posted (date of post, if you wante that) body (The update itself) Then just make a form, and when they press submit, add the information to the database. Then wherever you want them displayed, all you have to do is pull that information from the database. Quote Link to comment Share on other sites More sharing options...
MetroidMaster1914 Posted June 14, 2007 Author Share Posted June 14, 2007 Right, I should have been more specific in my first post. I've managed to figure out the part of writing the update to the file, I just don't know how to call up the information I need in the index file. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 14, 2007 Share Posted June 14, 2007 <?php $query = mysql_query("SELECT * FROM updates ORDER BY id DESC LIMIT 5"); while ($row = mysql_fetch_assoc($query)){ echo $row['update'].'<p>'; } ?> Just change it up to match your DB and how you want it displayed. Quote Link to comment Share on other sites More sharing options...
MetroidMaster1914 Posted June 27, 2007 Author Share Posted June 27, 2007 I don't store my updates in a mysql database, justas .html files in the directory "/archives/". Say you wrote an update at 2:55 pm on March 21, 2007. It would save the update to the file, "/archives/0703211455.html" Quote Link to comment Share on other sites More sharing options...
Casalen Posted June 27, 2007 Share Posted June 27, 2007 So you have separate HTML pages for each update? What exactly are the updates? I would use a database for most anything. You can use a text file if you don't have SQL access, but some more information on what exactly you're going for would help. If you still want to have separate pages, I think you'd want to have a database with the filenames of each update. The exception would be a directory listing could be changed into an array, but I doubt it can. Quote Link to comment Share on other sites More sharing options...
MetroidMaster1914 Posted June 27, 2007 Author Share Posted June 27, 2007 I'm actually trying to get it done with a directory array listing. I'm using a code like this: <?php $dir = '/archives'; $files = opendir($dir); while (false !== ($filename = readdir($dir))) { $files[] = $filename; } rsort($files) for ($i = 0; $i < 4; $i++){ include $files[$i]; } ?> However, when I try to view that, I get this message: Parse error: syntax error, unexpected T_FOR in /home/tartagli/domains/mhq.frih.net/public_html/admin/index.php on line 54 Line 54 is: for ($i = 0; $i < 4; $i++){ I don't know php well, so I can't tell what the syntax error is. Can anyone help? Quote Link to comment Share on other sites More sharing options...
Casalen Posted June 27, 2007 Share Posted June 27, 2007 Put a semicolon after rsort($files), see what that does. Not ending things properly is the most common problem I have constantly, so it makes sense. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted June 27, 2007 Share Posted June 27, 2007 as casalen wrote put a ; after rsort($files)... but next time try putting the data into a databasen, its much easier Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.