在joomla 2.5中从数据库中检索数据

时间:2013-08-11 07:34:12

标签: joomla

我有两张桌子:

  • 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 />";    


   }

1 个答案:

答案 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()