简体   繁体   English

joomla中的内部联接查询

[英]inner join query in joomla

I want to fire one complex query in my joomla site. 我想在我的joomla网站中触发一个复杂的查询。 I have written below code for it. 我已经为它写了下面的代码。

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('`chr`.`characteristic_id`,`chr`.`characteristic_value`,`prc`.`price_value`');
$query->from('`#___hikashop_product` AS `pdt`');
$query->join('inner', '`#__hikashop_variant` AS `vari` ON `pdt`.`product_id` = `vari`.`variant_characteristic_id`');
$query->join('inner', '`#__hikashop_characteristic` AS `chr` ON `vari`.`variant_characteristic_id` = `chr`.`characteristic_id`');
$query->join('inner', '`#__hikashop_price` AS `prc` ON `pdt`.`product_id` = `prc`.`price_product_id`');
$query->where('`pdt`.`product_id` = 68');
$db->setQuery($query);

Query is executing in my local mysql. 查询正在我的本地mysql中执行。 any help will be appreciated 任何帮助将不胜感激

You can try this 你可以试试这个

$db->setQuery("Your query");
$result = $db->query();

//if you need the count
$rowcount = $db->getNumRows();

//if the result is multiple rows
$result_array = $db->loadAssocList() or $db->loadObjectList();

//if the result is single row you can use
$result = $db->loadAssoc() or $db->loadObject();

To fire the query, all you need to do is: 要触发查询,您需要做的是:

$rows = $db->loadAssocList(); // or loadObjectList()

The above will put all of the rows into $rows 以上将所有行放入$rows

You can also fire the query without grabbing the rows with: 您还可以触发查询而无需使用以下方法获取行:

$db->query();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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