I have table in a sql db
CREATE TABLE `News` (
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`Title` varchar(100),
`Time` int(100)
PRIMARY KEY (`Id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;
and I have a page View.php
<?php
mysql_select_db($database_config, $config);
$query_m_list = "SELECT * FROM News Where Time='today' ORDER BY Id Asc";
$m_list= mysql_query($query_m_list, $config) or die(mysql_error());
$row_m_list= mysql_fetch_assoc($m_list);
$totalRows_m_list = mysql_num_rows($m_list);
?>
How can I view news by date Today or yesterday, or a specific date from the table?
Change your Time columns type to datetime
and then use the below query:
SELECT * FROM M_News Where date(`Time`)<=CURRENT_DATE()
AND date(`Time`)>=DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY)
ORDER BY Id Asc
Above query will give you the news of the today and yesterday.
since you store time as (int) data type you need to use time_ago function to calculate seconds,hours,days,weeks, month and year. you can download jquery timeago here TimeAgo
Once the timeago functions returns a specific value you can then ponder about fetching correct data you want.