rpV
rpV

Reputation: 17

SELECT COUNT with date and type

i have this function :

    function get_user_dep($userid)
    {
        $sql = mysql_query("SELECT COUNT(userid) AS total_dep FROM `userdep` WHERE `type` LIKE 'Depozitare' AND DATE(`date`) <= NOW() AND DATE(`date`) >= DATE_SUB(NOW(), INTERVAL 7 DAY)");
        $row = mysql_fetch_array($sql);
        $count = $row['total_dep'];
        if ($count > 1) {
            return 'Yes';
        } else {
            return 'No';
            }
    }
with database userdep
id/userid/type/date/amouth

i made with assoc, numrow , and it returns me No , and in the database i have more than 4 entrys in interval 7 days.

Upvotes: 0

Views: 296

Answers (2)

scottw33
scottw33

Reputation: 96

Sorry for having to ask this in an answer - my rep is too low. What field type is your date column? From what I just read in your comments on the answer below, the DATE field requires 'yyyy-mm-dd'.

Upvotes: 1

weinerk
weinerk

Reputation: 522

1) SQL is valid.

2) Change this:

$row = mysql_fetch_array($sql);

to this:

$row = mysql_fetch_array($sql, MYSQL_ASSOC);

or to this:

$row = mysql_fetch_assoc($sql);

3) Also you can try this to check what you received back from DB.

echo print_r($row, true);

Upvotes: 0

Related Questions