Page 1 of 1

query to get data for next available date if no data

Posted: Mon Jan 11, 2010 5:41 am
by peter162in
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?


?>

Re: query to get data for next available date if no data

Posted: Mon Jan 11, 2010 6:29 am
by VladSun
Please, use [ php ] [/ php] BBcode tags to surround your code.

You need a

Code: Select all

$row = mysql_fetch_assoc($result)
call in order to get the data.