php code Join three list

Kant

Member
My apprenticeship in php sql continues and I would be glad about some help.

I need the data as follows:

The data is searched from the element 'vorname' in the list 'benutzer'.

leftjoin vermietung 'fahrzeug_id' to fahrzeug'id'
leftjoin fahrzeug 'beauftragter_id to benutzer 'id'



Code:
$mydb = FabrikWorker::getDbo(false, 3);
$query = $mydb->getQuery(true);
$query->select('a.vorname')
   ->from('benutzer AS a')
   ->leftJoin('fahrzeuge as b ON b.beauftragter_id = a.id')
   ->leftJoin('vermietung as c ON c.fahrzeug_id = b.id')
   ->where('b.id = ' . $mydb->quote('{vermietung___fahrzeug_id_raw}'));
   $mydb->setQuery($myQuery);
return $mydb->loadResult();
 
Where are you doing this? In a calc element, or a form submission script, etc?

Which table is it on? So is {vermietung___fahrzeug_id_raw} an element on the form?

That looks like a valid query, as long as {vermietung___fahrzeug_id_raw} has the value you are expecting.

When debugging stuff like this, it often helps to be able to see the exact query being generated. Quick and dirty way is to to do ...

Code:
var_dump((string)$query);exit;

... just before you run the query (so penultimate line). So you'll get a blank page with just the debug output (unless this is happening on an AJAX call, in which case you have to look in the Network tab of dev tools in the browser to see the output).

A slightly better way is to use the 'dump' extension:

https://extensions.joomla.org/extension/j-dump/

... which will pop up a window with any results of doing ...

Code:
dump((string)$query, 'my query');

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top