how do i convert this php in cc6?

How to migrate custom PHP database operations to ChronoForms 6.

Overview

The user has existing PHP code that queries and updates database tables but wants to implement it using CF6's built-in tools.
Since the code is already functional, it can be kept as-is. Use a Custom Code action to run it and then pass the results to other CF6 actions as needed.

Answered
Connectivity v6
ze zest96 17 Dec, 2020
Hi all,
I have this (function:PHP) code which is currently running fine in CC6.
Need some directions of making this using the CC6 tools.
read, save, loop...

thanks
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `#__chronoforms_data_recommendation`
WHERE `applicant_exist` = '' AND `year` = '2021'";

$db->setQuery($query);
$recommendations = $db->loadObjectList();


foreach ( $recommendations as $r ) {

// get matching applications
$query = "
SELECT `aid`
FROM `#__chronoforms_data_scholarship-application`
WHERE `applicant_firstname` = '{$r->applicant_firstname}'
AND `applicant_lastname` = '{$r->applicant_lastname}'
AND `year` = '2021'
LIMIT 1 ;
";
$db->setQuery($query);
$applicant_aid = $db->loadResult();

// check if any matches found
if ( !$applicant_aid ) {
//echo '<i class="icon-ban-circle red"> <i>No matches found</i></i>';
continue;
}
// Update the recommendation
$query = "
UPDATE `#__chronoforms_data_recommendation`
SET `applicant_exist` = {$applicant_aid}
WHERE `aid` = {$r->aid}
";
$db->setQuery($query);
$db->query();
}
// TODO
// in applications {view:table} display count of how many recommendations have the same applicant aid).
//count on-the-fly and not write to table.
Max_admin Max_admin 23 Dec, 2020
Answer
if the code is working then keep it and return the value you need then use it in other actions, there is no need to build the code in CC6 tools
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.