Joomla:两个mysql查询模型函数和一个视图

时间:2012-11-20 14:57:34

标签: mysql model joomla2.5

我试图从一个视图运行两个模型函数。第一个查询似乎工作正常。 第二个查询返回一个空数组。我注意到在将查询打印到屏幕上时,查询似乎是连接在一起而不是分开的,如下所示:

JDatabaseQueryMySQL对象([db:protected] => JDatabaseMySQL对象([name] => mysql [nameQuote:protected] =>`[nullDate:protected] => 0000-00-00 00:00: 00 [dbMinimum:protected] => 5.0.4 [_database:JDatabase:private] => Curling_Schedule [connection:protected] =>资源ID#19 [count:protected] => 0 [cursor:protected] = >资源ID#72 [debug:protected] => [limit:protected] => 0 [log:protected] => Array()[offset:protected] => 0 [sql:protected] =&gt ; SELECT team_name,division FROM #_ autoschedTeams ORDER BY division [tablePrefix:protected] => encex [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected ] => [hasQuoted:protected] => [quoted:protected] => Array())[type:protected] => select [element:protected] => [select:protected] => JDatabaseQueryElement Object([name:protected] => SELECT [elements:protected] => Array([0] => sheet,id)[glue:protected] =>,)[delete:protec ted] => [update:protected] => [insert:protected] => [来自:protected] => JDatabaseQueryElement Object([name:protected] => FROM [elements:protected] => Array([0] => #__ autoschedPlayingSheets)[glue:protected] =>,)[join:protected] => [set:protected] => [where:protected] => [group:protected] => [有:受保护] => [columns:protected] => [values:protected] => [order:protected] => JDatabaseQueryElement Object([name:protected] => ORDER BY [elements:protected] => Array([0] => sheet)[glue:protected] =>,)[union:protected] => [autoIncrementField:protected] => )

型号:

    public function getTeams()
    {


            // Create a new query object.           
            $db = JFactory::getDBO();
            $query = $db->getQuery(true);
            // Select some fields
            $query->select('team_name, division');
            // From the hello table
            $query->from('#__autoschedTeams');
            $query->order('division');      
            $db->setQuery((string)$query);
            $teams = $db->loadResultArray();
            $div = $db->loadResultArray(1);
            $divs = array_unique($div);
            $result = [];
            foreach($divs as $key)
            {
                $result[$key] = [];
                foreach(array_keys($div, $key) as $index)
                {
                   array_push($result[$key], $teams[$index]);
                }
            }
            return $result;
 }
             public function getSheets()
    {

            // Create a new query object.           
            $db = JFactory::getDBO();
            print_r($query);
            $query = $db->getQuery(true);
            // Select some fields
            $query->select('sheet, id');
            // From the hello table
            $query->from('#__autoschedPlayingSheets');
            $query->order('sheet'); 
            //print_r($query);  
            $db->setQuery($query);
            $result = $db->loadResultArray();
            return $result;

    }

}

来自View的相关代码:

$teams_sched = $this->get('Teams');
$sheets_sched = $this->get('Sheets');

1 个答案:

答案 0 :(得分:1)

更改变量的名称并使用它进行检查。

如果您没有再次获得结果,请打印查询echo $query;并进行检查。

public function getSheets()
{      
    $db     = JFactory::getDBO();               
    $query  = $db->getQuery(true);                
    $query->select('sheet, id');
    $query->from('#__autoschedPlayingSheets');
    $query->order('sheet'); 
    $db->setQuery($query);
    $Sheets = $db->loadResultArray();

    print_r($Sheets);

    return $Sheets;

}