我试图从一个视图运行两个模型函数。第一个查询似乎运行正常。
第二个查询返回一个空数组。我在将查询打印到屏幕上时注意到,查询看起来似乎是在联接在一起,并且不是分开的,例如:

JDatabaseQueryMySQL Object([db:protected] => JDatabaseMySQL Object([name] => mysql [nameQuote:protected] =>`[nullDate:protected] => 0000-00-00 00:00:00 [dbMinimum:protected] = > 5.0.4 [_database:JDatabase:private] => Curling_Schedule [连接:受保护] =>资源id#19 [count:protected] => 0 [cursor:protected] =>资源id#72 [debug:protected] = > [limit:protected] => 0 [log:protected] => Array()[offset:protected] => 0 [sql:protected] =>选择team_name,除法##autoschedTeams ORDER BY除法[tablePrefix:protected] = > encex [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [hasQuoted:protected] => [quoted:protected] => Array())[type:protected] =>选择[element:protected] => [select:protected] => JDatabaseQueryElement对象([name:protected] => SELECT [elements:protected] =>数组([0] => sheet,id)[glue:protected] = >,)[删除:受保护] => [更新:受保护] => [插入:受保护] => [来自:受保护] => JDatabaseQueryElement对象([name:protected] => FROM [elements:protected] => Array([0] => #__autoschedPlayingSheets)[glue:protected] =>,)[join:protected] => [set:protected] => [where:protected] => [group:protected] => [having:protected] => [columns:protected] => [values:protected] => [order:protected] => JDatabaseQueryElement Object([name:protected] => ORDER BY [元素:受保护的] =>数组([0] =>表格)[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;

    }


}

查看相关代码:

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

最佳答案

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

如果没有再次得到结果,请打印查询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;

}

关于mysql - Joomla:具有一个 View 的两个mysql查询模型函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13475888/

10-15 21:19