我有两张桌子:
agahi:(agahi_id,ostan,car_id,出版)
user_agahi(user_agahi,ostan,tarafeagahiuser,出版)
我使用下面的代码,但我无法检索数据
class modostanHelper
{
public function retrieve()
{
$db=JFactory::getDBo();
$sql="create view agahi as(select ostan,count(id_useragahi) as text_agahi from #__npco_useragahi where published=1 group by ostan) ";
$db->setQuery($sql);
$db=JFactory::getDBo();
$sql_1="create view useragahi AS (select ostan,count(id_agahi) as text_useragahi from #__npco_agahi where published=1 group by ostan) ";
$db->setQuery($sql_1);
$db=JFactory::getDBo();
$sql_2="select * from agahi,useragahi where agahi.ostan=useragahi.ostan";
$db->setQuery($sql_2);
return $db->loadAssocList();
}
}
在文件default.php
中,我使用下面的代码
<?php
defined('_JEXEC') or die();
$obj=modostanHelper::retrieve();
foreach($obj as $item)
{
$count= $item['text_agahi']+$item['text_useragahi'];
echo "<a href='' style='text-decoration:none'>".">>".$item['ostan']. " [".$count."]</a><br />";
}
答案 0 :(得分:0)
后
$db=JFactory::getDBo();
$sql="create view agahi as(select ostan,count(id_useragahi) as text_agahi from #__npco_useragahi where published=1 group by ostan) ";
$db->setQuery($sql);
执行查询:
$db->query()