简体   繁体   中英

join with JDatabase doesn't work

I'm beginner with Joomla! and i'm trying to get informations from my database, but it doesn't work, Joomla! display a blank page, which means there is an execution error with my PHP code.

Here is the code of my request :

$query
->select($db->quoteName(array('orders.order_id', 'user.first_name', 'user.last_name')))
->from($db->quoteName('#__orders', 'orders'))
->join('LEFT', $db->quoteName('#__userinfos', 'user').' ON ('.$db->quoteName('orders.user_id').' = '.$db-quoteName('user.user_id') .')')
->where($db->quoteName('address_type').' = '.$db->quote('BT'));

I know the error comes from the join function, because when i comment it, there is no error

Here is the SQL request i want to call

SELECT orders.order_id, users.first_name, users.last_name 
FROM prefix_orders orders LEFT JOIN prefix_userinfos users
ON orders.ser_id = users.user_id
WHERE address_type = 'BT'");

thanks

You have a syntax error in the last quote of the join method:

 $db-quoteName('user.user_id')

instead of

$db->quoteName('user.user_id')

Illusive one, I would say.

您需要指定“ address_type”列的来源(用户或订单表),否则mysql无法在查询中找到它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM