0

我开始为 Drupal 构建主题。

我有一个关于drupal查询的问题,但我没有找到任何答案......

我的一个模块中有一个 db_query,但只返回几行(总是 13 行,表有 20 行)如何从一个表中选择所有行?

我的查询是这样的

$result = db_query("SELECT * FROM bv_calendar c INNER JOIN bv_countries p ON c.country_id = p.country_id INNER JOIN bv_vaccinate v ON c.vaccinate_id = v.vaccinate_id ORDER BY $orderby ASC");

while ($class = $result->fetchAssoc()) {
    $classes[$class["calendar_id"]] = $class;
}

如何获取所有行?

谢谢

4

1 回答 1

2

From the looks of it I'd say you're not getting all the rows from the *bv_calendar* because you're using INNER JOIN on your SQL query which requires to be matching records on your *bv_countries* and *bv_vaccinate* tables.

Try replacing the INNER JOIN for LEFT JOIN as in the later "If there is no matching row for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table." from http://dev.mysql.com/doc/refman/5.0/en/join.html.

If that's the result you want then your SQL query should be:

SELECT * FROM bv_calendar c LEFT JOIN bv_countries p ON c.country_id = p.country_id LEFT JOIN bv_vaccinate v ON c.vaccinate_id = v.vaccinate_id ORDER BY $orderby ASC
于 2013-04-16T17:17:45.600 回答