I need help converting the following MySQL code to a Drupal 7 API call.

select count(*) from cugoslide where cugoslide_status = 'A'
                           AND sysdate() >= cugoslide_begin_date
                           AND sysdate() <= cugoslide_end_date

I got this working by doing the following:

$sql = db_query("select * from cugoslide where cugoslide_status = 'A'
                           AND sysdate() >= cugoslide_begin_date
                           AND sysdate() <= cugoslide_end_date");
$result = db_query($sql)->rowCount();

Hope this helps someone later.

Comments

kunalkursija’s picture

You can also use the combination of db_select() and db_and() to acheive the output.

Here is the api for db_and().