Using the PHP code box

fix a database connection error in ChronoForms when using a left join.

Overview

The error occurs because the JFactory class is not within the PHP namespace used by ChronoForms.
Modify the database connection line to use the global namespace by adding a backslash before JFactory.

Answered
ChronoForms v6
st stikkimorey 04 Aug, 2018
Hi I would be very grateful if someone could help me out.

I have been having trouble getting a connection to 2 tables using a left join inside Chronoforms 6, so I modelled it up in PHP in a custom html module in Joomla, and the following code works. But I would like to be working in Chronoforms, so I put it in a PHP object in Setup.

I get the following error however: Call to a member function select() on null

Would somebody please let me know how I can adapt the database connection to work in Chronoforms?
​[pre]$db = JFactory::getDbo();

$query = $db->getQuery(true);
[br]$query -> select ('assets.asset_id, assets.type_of_resource, bookings.start_date, bookings.request_delivery');[br]$query -> from('#__tblAssets AS assets');[br]$query ->leftjoin('#__tblBookings AS bookings ON assets.asset_id = bookings.asset_id');[br][br]$db->setQuery($query);[br]//loadObjectList to get all results in the array;[br]$results=$db->loadObjectList();[br][br]echo'<tr><td>';[br]echo $d->asset_id .'</td>';[br]echo '<td>'. $d->start_date .'</td>';[br]echo '<td>'. $d->end_date .'</td>';[br]echo '<td>'. $d->type_of_resource .'</td>';[br]echo '<td>'. $d->request_delivery .'</td>';[br][br]echo'</tr>';[br][br]foreach($results as $d){[br][br]echo'<tr><td>';[br]echo $d->asset_id .'</td>';[br]echo '<td>'. $d->start_date .'</td>';[br]echo '<td>'. $d->end_date .'</td>';[br]echo '<td>'. $d->type_of_resource .'</td>';[br]echo '<td>'. $d->request_delivery .'</td>';[br][br]echo '</tr>';[br]}[br][/pre][br]echo '</table>';[br][br]
Gr GreyHead 04 Aug, 2018
Answer
Hi stikkimorey,

I suspect that the problem is that ChronoForms now uses a PHP Namespace and JFactory is not in it. Please try changing the first line to
$db = \JFactory::getDbo();
and see if that makes a difference.

Bob
st stikkimorey 04 Aug, 2018
Many thanks Bob - that has got me closer to a solution and I can create the array now.

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