PHP Mysql Statement Help!

I am having trouble with mysql statement inside php, Any help would be greatly appreciated.

The working statement is:
$sql = ‘SELECT calendar.datefield AS DATEALL, IFNULL( COUNT( MytableA.My_ID ) , 0 ) AS Total_Report FROM ( SELECT My_ID, Report_Date, Person_ID FROM Mytable WHERE Mytable.Person_ID LIKE ‘.$_SESSION[‘Person_id’].’) AS MytableA RIGHT JOIN calendar ON ( DATE( MytableA.Report_Date ) = calendar.datefield ) WHERE (calendar.datefield BETWEEN ‘2010-07-23’ AND ‘2011-07-23’)\ GROUP BY CONCAT( year( DATEALL ) , month( DATEALL ) ) ORDER by DATEALL’;

The only difference I added is the date variable and is not working, I am running on mysql5 server

$sql1 = ‘SELECT calendar.datefield AS DATEALL, IFNULL( COUNT( MytableA.My_ID ) , 0 ) AS Total_Report FROM ( SELECT My_ID, Report_Date, Person_ID FROM Mytable WHERE Mytable.Person_ID LIKE ‘.$_SESSION[‘Person_id’].’) AS MytableA RIGHT JOIN calendar ON ( DATE( MytableA.Report_Date ) = calendar.datefield ) WHERE (calendar.datefield BETWEEN ‘’.date( ‘Y-m-j’ ).’’ AND ‘’.date(“Y-m-j”,strtotime("-365 day")).’’) GROUP BY CONCAT( year( DATEALL ) , month( DATEALL ) ) ORDER by DATEALL’;

Thanks!

Hi there,

Try changing:
[php].date( ‘Y-m-j’ ).’’ AND ‘’.date(“Y-m-j”,strtotime("-365 day")).[/php]

to:
[php].date(“Y-m-j”,strtotime("-365 day")).’’ AND ‘’.date( ‘Y-m-j’ ).[/php]

(Put the date functions the other way round)

:slight_smile: thank you so much for your time! Smokey PHP It worked like a charm.

Sponsor our Newsletter | Privacy Policy | Terms of Service