1

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I'm trying to build a MySQL query which selects all activities within one month. So far, I've got this:

public static function allMonthlyActivities($db, $startdate, $enddate) {
        $sql = "SELECT shortdate FROM calendar WHERE date >= $startdate and <= $enddate";
        $result = $db->listing($sql);
        return $result;
}

And the PHP executing this is:

$list = Calendar::allMonthlyActivities($_DB, '2013-02-01', '2013-02-25');

But for some reason, I get this error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in... 

Here is my database structure:

How do I pass dates correctly (which format) to my SQL statement so all dates from 1 month return?

EDIT - here is my listing function

public function listing($sql) {
    $result = mysql_query($sql, $this->_connection);
    while($row=mysql_fetch_array($result)) {
      $return[] = $row;
    }
    return $return;
  }
Community
  • 1
  • 1
Michiel
  • 7,571
  • 16
  • 59
  • 111

2 Answers2

2

I suspect you have an error in your query, change this:

$result = mysql_query($sql, $this->_connection);

To:

$result = mysql_query($sql, $this->_connection) or die(mysql_error());

Your data type for shortDate is varchar, try changing it to date to see if problem is resolved.

Also date is reserved keyword, use backtick chars eg ` for it.

Sarfraz
  • 367,681
  • 72
  • 526
  • 573
0

Are you sure you have a coloumn named date because MySQL has DATE as a keyword. Most likely your query is wrong.

check123
  • 1,979
  • 2
  • 22
  • 28