views:

26

answers:

1

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;
    }
}
+1  A: 

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

ar
Thank you, I knew I was overlooking something, I thought that if joins automatically select the whole table. Thanks again.
RobertPitt
You really really should be explicitly specifying the columns that you want. Otherwise, when the schema changes your existing queries may stop working.
ar
Yes I know this, and they will be specified but as my system is still under way, im quickly getting the basics in and the ill fine tune everything.
RobertPitt