Overview
This tutorial demonstrates how to implement a custom SQL query as a data source for Chronoforms views in versions 6, 7, or 8. It provides step-by-step instructions, including adding a PHP action with code to execute the query and load results. You can then customize the SQL and use the returned data in Dropdown, Checkboxes, Radios, Table, or other list views.
In this tutorial we will show you how to use your own full custom SQL query as a data source for any Chronoforms view, this technique can be implemented in Chronoforms version 6,7 or 8
First, add a PHP action to your form and paste this code:
// Import Joomla's database classes
use Joomla\CMS\Factory;
use Joomla\CMS\Table\Table;
// Get the database connection
$db = Factory::getDbo();
// Create a new query object
$query = $db->getQuery(true);
// Execute the query
$db->setQuery("SELECT * FROM #__chronoforms8");
// Load the results as an array of objects
$results = $db->loadAssocList();
return $results;

Now you may customize the SQL query to anything you like, and use {var:php_action_name} as your data source in Dropdown, Checkboxes, Radios or Table view or any other lists which need a data source.

How to use the Read Data action for custom SELECT queries
if you want to use the Read Data action instead of the full custom PHP action solution, then you can use the SQL Code behavior as shown

How to use the IN rule in your SELECT statement
In order to match multiple values, you can use the "in" shortocode function as shown:

Where {var:variable_name} holds an array of values, the final query will be something like this: IN ('u1', 'u2', 'u3')

Comments