CODEIGNITER中错误使用UNION和ORDER BY - Mysql

时间:2018-01-25 12:35:22

标签: php mysql codeigniter

我有这个问题:

SELECT *
FROM videos
WHERE Autor = 'LittleBabyBum ® Español'
ORDER BY RAND()
LIMIT 10)
UNION (
SELECT *
FROM videos
WHERE Categoría = 'Música - Niños'
  AND Autor <>'LittleBabyBum ® Español'
ORDER BY RAND()
LIMIT 5

它的效果非常好。

但实际上我在codeigniter中有问题...有人知道如何使用它吗?

感谢。

1 个答案:

答案 0 :(得分:0)

模特中的

function result() {
    $query = $this->db->query("(SELECT * FROM videos where Autor = 'LittleBabyBum ® Español' order by RAND() LIMIT 10) UNION (SELECT * FROM videos WHERE Categoría = 'Música - Niños' AND Autor <>'LittleBabyBum ® Español' order by RAND() lIMIT 5)");
    return $query->result_array();
}

在控制器中:

$array = $this->MyModel->result();