RobertPitt
RobertPitt

Reputation: 57268

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..

Theres no error what so ever, Ive tested in PHPMyAdmin and same result, Here's the PHP Code used

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;
    }
}

Upvotes: 0

Views: 133

Answers (1)

a'r
a'r

Reputation: 36999

Your query is only selecting columns from the downloads table - d.*. You just need to specify the columns that you need from categories.

Upvotes: 1

Related Questions