简体   繁体   中英

inner join query in joomla

I want to fire one complex query in my joomla site. 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. 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

You can also fire the query without grabbing the rows with:

$db->query();

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