I'm trying to get data from multiple tables and I've ended with this error: SQL: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p.firstname' in 'field list'
$criteria = new CDbCriteria;
$criteria->select = 'ohu_id, hash, p.firstname, p.surname, p.city, u.email AS Email';
$criteria->join = 'LEFT JOIN `profiles` p ON p.user_id = user_id';
$criteria->join = 'LEFT JOIN users u ON user_id = u.id';
$criteria->condition = 'offer_id = :oID';
$criteria->params = array(':oID' => $_GET['id']);
$model = MyModel::model()->findAll($criteria);
Anyone know what I'm doing wrong? Or is there better way to get related data?
You are making the same mistake I made hehe.
You are overwriting the first join with the second one, instead of appending the second join.
$criteria->join = "join ...."; //first join
$criteria->join .= "join ...."; //second join
cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With