简体   繁体   English

极其简单的MySQL查询无法正常工作

[英]Extremely simple MySQL Query not working

Im a little puzzled here, can someone just look over this query and tell me am i doing anything wrong? 我在这里有点困惑,有人可以看看这个查询并告诉我我做错了什么吗?

SELECT d.* FROM as_downloads d LEFT JOIN as_categories c ON (d.download_category_id = c.category_id) WHERE d.download_category_id != -1 LIMIT 30

Fetching the rows from the as_downloads table but not joining the categories table.. as_downloads表中获取行,但不加入类别表。

Theres no error what so ever, Ive tested in PHPMyAdmin and same result, Here's the PHP Code used 我曾经在PHPMyAdmin中测试过,并且结果相同,这是没有错误,这是使用的PHP代码

class Model_Downloads extends ModelType_PDO
{
    public function fetchDownloads($limit)
    {
        $p = Registry::get('Config')->Database->prefix;

        $query = "SELECT d.* FROM ".$p."downloads d LEFT JOIN ".$p."categories c ON d.download_category_id = c.category_id WHERE d.download_category_id != -1 LIMIT :limit";
        $this->query = $this->prepare($query);
        $this->query->bindValue(':limit',$limit,PDO::PARAM_INT);

        if($this->query->execute())
        {
            return $this->query->fetchAll(PDO::FETCH_CLASS);
        }
        return false;
    }
}

Your query is only selecting columns from the downloads table - d.* . 您的查询仅从下载表d.*选择列。 You just need to specify the columns that you need from categories. 您只需要从类别中指定所需的列即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM