Query Row Count Between Dates | Halp

SoilentRed

Caaan do!
I have an element for start date, end date and a database join that gives a user id.

I have a fabrik table that with a bunch of data submitted by a user. I'm trying to put together a query that returns the row count of the selected user. I'm using calc with ajax to get the value.

Here's the code I'm tinkering with
Code:
$cbid = (int)'{afab_kpi_report___community_builder_raw}';
$start = '{afab_kpi_report___start_date}';
$end = '{afab_kpi_report___end_date}';

$db = JFactory::getDBO();
$db->setQuery('SELECT COUNT(*) FROM 07_new_member WHERE 07_new_member.agent_user_id = ' . $cbid . ' AND 07_new_member.date_time BETWEEN ' . $start . ',' . $end .'' );
$count =  $db->loadResult();
return $count;
And here's the error I'm getting
Code:
An error has occurred.
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
I've tried formatting the date with , for example $startDate = strtotime($start);
but any time I query the date range, this wants to break. Any ideas?
 
  • BETWEEN syntax is BETWEEN ... AND ...
  • You have to quote dates (and maybe you have to use {..._raw} to get the mySQL formatted date)
  • (You should ALWAYS quote ($db->quote()) ALL user input because of security reasons anyway)
  • $end .'' ); 2 quotes?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top