Forums

Run php SQL code in Custom Code areas

terry 29 Jul, 2016
Hi,

I want to run some custom code as the HTML page is presented. I need to run some sql to update a table filling in some total fields before I download to .csv. In another form I need to truncate a table and then run sql to insert rows by selecting from another table and then download the previously truncated and reloaded table to .csv.

Can this level of sql be run in custom code area (or anywhere else) within a form?

Thanks,
Terry Banks
Holy Trinity Episcopal Church
Fruitland Park, FL USA
GreyHead 30 Jul, 2016
Hi terry,

You can run pretty much any PHP & MySQL In a Custom Code action on the Setup tab of your form. Here's an outline I have in a keyboard macro
$db = \JFactory::getDBO();
$query = "
    SELECT ``
        FROM `#__`
        WHERE `` = '' ;
";
$db->setQuery($query);
$data = $db->loadObjectList();
//$data = $db->loadResult();

If you want to run an update then use $db->execute($query);

Bob
This topic is locked and no more replies can be posted.