Get data for a next available date from mysql database if data not available for the specified date.
Data arranged in table date wise. But for some date there is no data.
include "dbconect.php";
$date=$_GET['date'];
$sql = "SELECT * FROM table1 WHERE date='$date'";
$result = mysql_query($sql) or die(mysql_error());
if ( empty($result)) {
$dif2=strtotime ( '-1 day' , strtotime ( $date ) ) ;
$date2=date ( 'Y-m-d' , $dif2 ) . "<br />\n" ;
echo"$date2". "<br />";
}
$sql = "SELECT * FROM table1 WHERE date='$date2'";
I stuck ! any help how to proceed ahead? any way?
?>
query to get data for next available date if no data
Moderator: General Moderators
-
peter162in
- Forum Newbie
- Posts: 12
- Joined: Mon Jul 06, 2009 11:37 am
Re: query to get data for next available date if no data
Please, use [ php ] [/ php] BBcode tags to surround your code.
You need a call in order to get the data.
You need a
Code: Select all
$row = mysql_fetch_assoc($result)There are 10 types of people in this world, those who understand binary and those who don't