[size=“4”]I want to get description, (first_name,last_name,’-’,title) as title from team table and name as image from image_gallery table by using id from team table
I am Using Windows 10 OS, XAMPP Server with PHP 5.6 aand Mysql 5.6, Yii 2.0.7
I have read from other forum and modify my code by i still not get intended result
When I use without
->select()
i get output but i want output with
->select(["CONCAT(first_name,space(5),last_name,space(10),' - ',space(10),title) as title","name as image","description"])
[/size]
CREATE TABLE `quickbrain_team` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`first_name` varchar(45) NOT NULL COMMENT 'First Name',
`middle_name` varchar(45) DEFAULT NULL COMMENT 'Middle Name',
`last_name` varchar(45) NOT NULL COMMENT 'Last Name',
`title` varchar(45) NOT NULL COMMENT 'Title',
`designation` varchar(45) DEFAULT NULL COMMENT 'Designation',
`photo` int(11) DEFAULT NULL COMMENT 'Photo',
`description` text COMMENT 'Description',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Created',
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Updated',
`email` varchar(50) DEFAULT NULL COMMENT 'Email',
`mobile` varchar(50) DEFAULT NULL COMMENT 'Mobile',
`facebook` varchar(200) DEFAULT NULL,
`twitter` varchar(200) DEFAULT NULL,
`googleplus` varchar(200) DEFAULT NULL,
`linkedin` varchar(200) DEFAULT NULL,
`status` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
KEY `fk_photo_idx` (`photo`),
CONSTRAINT `fk_photo` FOREIGN KEY (`photo`) REFERENCES `quickbrain_image_gallery` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE
)
CREATE TABLE `quickbrain_image_gallery` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(300) NOT NULL COMMENT 'Name',
`caption` varchar(300) DEFAULT NULL COMMENT 'Caption',
`path` varchar(50) NOT NULL COMMENT 'Path',
`size` double(15,2) NOT NULL COMMENT 'Size',
`type` varchar(10) NOT NULL COMMENT 'Type',
`created_at` varchar(30) DEFAULT NULL COMMENT 'Created',
`updated_at` varchar(30) DEFAULT NULL COMMENT 'Updated',
PRIMARY KEY (`id`),
KEY `name_ig_idx` (`name`)
)
public function getPhotos()
{
return $this->hasOne(Images::className(), ['id' => 'photo'])->from(Images::tableName()." i");
}
$model=\backend\models\Team::find()
->from(Team::tableName()." t")
->select(["CONCAT(first_name,space(5),last_name,space(10),' - ',space(10),title) as title","name","i.id"])
->joinWith("photos",true)->where('t.id=:page',[':page'=>$page])->one();