Comparing dates from Mysql and PHP
Posted: Tue Nov 09, 2010 7:42 pm
Hi, I am a PHP beginner, I am working this code and I need help, And kinda stack of it.
I have a database with 5 fields(id, date, time , title and description). This is what I want to do;
I want my script to go into the database fetch the date and compares dates if both days are equal, it should echo or read the dates as one and the titles and descriptions will be display with one dates that corresponds to the date taken from Mysql but when the dates are not equal it will display another dates. Your help is really highly appreciated guys.. Thanks in advance.
Example :
If dates are similar it will display in one category of dates
November 9, 2010 Updates
Sample 1
This is a description.
Sample 2
This is a description.
Sample 3
This is a description.
But if the dates is not equal it will display another date category
November 8, 2010 Updates
Sample 1
This is a description.
Sample 2
This is a description.
Any help please? What should i do after this codes?
But my codes does not work. It display all the dates even if it is similar dates. Can any one help me please.. 
I have a database with 5 fields(id, date, time , title and description). This is what I want to do;
I want my script to go into the database fetch the date and compares dates if both days are equal, it should echo or read the dates as one and the titles and descriptions will be display with one dates that corresponds to the date taken from Mysql but when the dates are not equal it will display another dates. Your help is really highly appreciated guys.. Thanks in advance.
Example :
If dates are similar it will display in one category of dates
November 9, 2010 Updates
Sample 1
This is a description.
Sample 2
This is a description.
Sample 3
This is a description.
But if the dates is not equal it will display another date category
November 8, 2010 Updates
Sample 1
This is a description.
Sample 2
This is a description.
Any help please? What should i do after this codes?
Code: Select all
<?php
$result = mysql_query("SELECT * FROM tbl_localnews");
while($rows = mysql_fetch_array($result) ){
//If the dates in database is exist in many times.
//Display it in one date category.
if ( $rows > 1 ) {
?>
<h3 class="update">
<em>News for <?php print $rows['date']; ?></em><em style="font-size:12px; float:right;">Updated <?php echo $rows['time'] ?></em></h3>
<?php
// If Not the same Display dates in another category.
}else{?>
<h3 class="update">
<em>News for <?php print $rows['date']; ?></em><em style="font-size:12px; float:right;">Updated <?php echo $rows['time'] ?></em></h3>
<?php
}
}
?>