Hey Daniweb lovers,

I am using a cake php framework to develop my application. The problem I am facing at the moment is that I am trying to use two different tables (let's call them users and products.) I can select users from the users table. But, I have got a query in my function that is in the controller. It is something like

        $query= $this->User->query("SELECT username,prod_id,prod_name FROM users,products;");

        $this->set('usernames', $query); 

I have also created a model for the products table.. I don't know why it is not working..

Hear from you, folks ...

6 Years
Discussion Span
Last Post by rotten69

The 2 tables in your example don't sound connected? you need to tell mysql what to join the 2 tables on eg.

SELECT username,prod_id,prod_name FROM users LEFT JOIN products on users.uid = products.uid

I think mysql will default use the primary keys, if they dont match it can't join so you have to tell it specifically which field

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.