Running Chronoforms 7 on Wordpress. Any somewhat simple way I can make a DB call and get a count of records returned back?
I'm able to figure out making the call and getting back the responses, but I'm trying to limit by a specific field and if the count comes back more than 3 times, stop the form processing and give a message.
So far using Read Data and specifying the Where clauses works great.
I've tried using the SQL Data action and it bombs my site whenever I use it.
Can anyone help. I've been racking my brain.
I'm able to figure out making the call and getting back the responses, but I'm trying to limit by a specific field and if the count comes back more than 3 times, stop the form processing and give a message.
So far using Read Data and specifying the Where clauses works great.
I've tried using the SQL Data action and it bombs my site whenever I use it.
Can anyone help. I've been racking my brain.
You can do get row counts easily with some PHP code.
If you're using a Read Data function, {fn:read_data} will return {var:read_data} as an array. Just use PHP to count the items in the array. To retrieve {var:read_data} in PHP code, use:
The exact code depends on what your returned array look like from {fn:read_data}. However, this is AFTER the DB query has been made and processed.
From your post it sounds like you want it to stop WHILE doing the DB query if the count reaches 3? If you want to do it this way, you'll need to code the whole query in PHP.
If you're using a Read Data function, {fn:read_data} will return {var:read_data} as an array. Just use PHP to count the items in the array. To retrieve {var:read_data} in PHP code, use:
$array = $this->get("read_data.Model");
echo count($array);
The exact code depends on what your returned array look like from {fn:read_data}. However, this is AFTER the DB query has been made and processed.
From your post it sounds like you want it to stop WHILE doing the DB query if the count reaches 3? If you want to do it this way, you'll need to code the whole query in PHP.
here is a post on how to count rows and use them in PHP:
https://www.chronoengine.com/forums/topics/view/111004/the-id-number-in-the-text-field-automatically-changes-each-time-it-is-sent#p402564
https://www.chronoengine.com/forums/topics/view/111004/the-id-number-in-the-text-field-automatically-changes-each-time-it-is-sent#p402564
You need to login to be able to post a reply.