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

Recommended Answers

All 4 Replies

users and products table?

Yeah, I am using two different tables.

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

Thanks for thehelp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.