john010117 Posted January 7, 2007 Share Posted January 7, 2007 On my index page, I have a news section. No php needed for that. But I want the website to automatically archive old news when the next day comes. So, if I type in index.php, it should automatically get the news for today (but I'm typing up the news). Sorry if this doesn't make sense. I want to have something like this (see the date at the top and the arrows?). How do you do that? Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 Can anybody help? Please? Link to comment Share on other sites More sharing options...
jesh Posted January 8, 2007 Share Posted January 8, 2007 If all of your news items are in a database, you can use PHP to determine today's date and a SQL query to only grab the headlines for news items that are from the current day (or after some arbitrary hour like today at 12AM). SELECT newsID, headline FROM news WHERE date > '2007-01-08 00:00:00' (query may be different depending on your database) Link to comment Share on other sites More sharing options...
john010117 Posted January 9, 2007 Author Share Posted January 9, 2007 If all of your news items are in a database, you can use PHP to determine today's date and a SQL query to only grab the headlines for news items that are from the current day (or after some arbitrary hour like today at 12AM). SELECT newsID, headline FROM news WHERE date > '2007-01-08 00:00:00' (query may be different depending on your database) Well, so far I have this code.<?php// Connection information$db_host = "localhost"; $db_user = "**"; $db_pass = "**"; $db_name = "**"; // Connect to server$dbac = mysql_connect($db_host,$db_user,$db_pass); // Select databasemysql_select_db ($db_name) or die ("Cannot connect to database"); // Change is here added [ = '{$_GET['date']}' ] to end. Which get ?date=____ from url.$result = mysql_query("SELECT * News FROM news WHERE Date = '{$_GET['date']}' ORDER BY Time");if ($result && mysql_num_rows($result)) { $numrows = mysql_num_rows($result); $rowcount = 1; while ($row = mysql_fetch_assoc($result)) { while(list($var, $val) = each($row)) { print "<B>$var</B>: $val<br />"; } print "<br />"; ++$rowcount; } }?> I store the news by date, so whenever I type index.php?date=2007-01-06, it'll give me all the news for ONLY that day. Now I'm trying to figure out how to get today's news when I just type in index.php. Any ideas? Link to comment Share on other sites More sharing options...
Guest Kiwi Posted January 9, 2007 Share Posted January 9, 2007 You can implement something like this: if ( !isset ( $_GET [ 'date_thingy'] ) ) // If ?date_thingy is not set{ // Make the query without WHERE clausule}else{ // Make query with WHERE clausule} But.. isn't it a better idea if you make this with 24hrs ago. 'Cause when it's 00:01hrs, there is no news, that kinda looks weird. Link to comment Share on other sites More sharing options...
jesh Posted January 9, 2007 Share Posted January 9, 2007 Or, check to see if the date is set in the URL (like the example from Kiwi). If it is set, then store that value in some $date variable. If it is not set, then set $date to today's date.Then use that $date in your WHERE clause. Link to comment Share on other sites More sharing options...
john010117 Posted January 9, 2007 Author Share Posted January 9, 2007 Ok. I'm sorry for being a n00b. Can you be more specific with the coding? I've read some PHP tuturiols on dates, but I can't seem to understand how it automatically sets to today's date AS SOON as the date changes. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 10, 2007 Share Posted January 10, 2007 Check this reference:http://www.php.net/manual/en/ref.datetime.phpScroll down to see the list of date/time functions. You can use the time function to return the current timestamp, the date function will also default to the current time, and mktime will give you the timestamp for a date you specify.The only caveat is that it uses the server time. If your server is hosted on Christmas Island, then the time returned by these functions will be in their time zone, unless you specify otherwise. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now