mysql DATE_ADD usage in PHP
Posted: Sat Apr 11, 2009 6:37 pm
Hi all, I'm trying to create a report using a collection of records dated within the 7 days follow a given date. The sql statement I'm using is
The above statment works fine directly on the command line, and if I use in in a single PHP page as part of a simple script Like this:
But if I call it from within a class method like this
It fails completely.
My question(s) is: Is there a better way to archive this? what is wrong in the statement that may be preventing it form returning a result when used in a class? Any ideas would be helpful I have spent way too much time on this and need a fix asap, thanks all.
Code: Select all
$query = "SELECT * FROM swnb_cards WHERE department = '$department' AND issue_date BETWEEN '$start_date' AND DATE_ADD('$start_date', INTERVAL $interval $unit )";Code: Select all
$sqlOBJ = new mysql ( );
$department = 1;
$start_date = "2009-03-12";
$interval = 7;
$unit = "DAY";
$query = "SELECT * FROM swnb_cards WHERE department = '$department' AND issue_date BETWEEN '$start_date' AND DATE_ADD('$start_date', INTERVAL $interval $unit )";
$sqlOBJ->query ( $query );Code: Select all
function per_department($start_date, $department, $interval, $unit) {
// do query
$query = "SELECT * FROM swnb_cards WHERE department = '$department' AND issue_date BETWEEN '$start_date' AND DATE_ADD('$start_date', INTERVAL $interval $unit )";
$this->sqlOBJ->query($query);My question(s) is: Is there a better way to archive this? what is wrong in the statement that may be preventing it form returning a result when used in a class? Any ideas would be helpful I have spent way too much time on this and need a fix asap, thanks all.