ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Using the PHP code box

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]
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
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.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com