I'm trying to convert this mysql query to active record, but the like clause not working properly and not return any output. I don't get what I missed actually.
table schema:
tbl_batch:
CREATE TABLE `tbl_batch` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Round` varchar(5) COLLATE utf8_bin NOT NULL,
`BatchID` varchar(255) COLLATE utf8_bin NOT NULL,
`TSP` varchar(10) COLLATE utf8_bin NOT NULL,
`Slot` tinyint(1) NOT NULL,
`Trade` int(11) NOT NULL,
`StartDate` date NOT NULL,
`EndDate` date NOT NULL,
PRIMARY KEY (`BatchID`),
UNIQUE KEY `ID` (`ID`),
UNIQUE KEY `BatchID` (`BatchID`),
UNIQUE KEY `BatchID_2` (`BatchID`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
tbl_tsp_info:
CREATE TABLE `tbl_tsp_info` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`TSP` varchar(10) NOT NULL,
`Name` varchar(50) NOT NULL,
`Email` varchar(50) NOT NULL,
`Website` varchar(50) NOT NULL,
`ContactPerson` varchar(50) NOT NULL,
`ContactPhone` varchar(11) NOT NULL,
`Phone` varchar(11) NOT NULL,
`Fax` varchar(11) NOT NULL,
`Address` varchar(255) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
tbl_instructor_info
CREATE TABLE `tbl_instructor_info` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`InstructorID` varchar(7) NOT NULL,
`Name` varchar(50) NOT NULL,
`Mobile` varchar(11) NOT NULL,
`Email` varchar(50) NOT NULL,
`Trade` int(1) NOT NULL,
`TSP` int(1) NOT NULL,
`Slot` tinyint(1) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `InstructorID` (`InstructorID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8
MySQL Query: (Working perfectly)
SELECT BatchID
from tbl_batch
WHERE Round='7'
AND BatchID LIKE concat('%', (SELECT ShortCode FROM tbl_tsp_info WHERE id=
(SELECT TSP FROM tbl_instructor_info WHERE Email='[email protected]')),'%')
Codeigniter Model:
public function get_batch_byUser($email=string) {
$this->db->select('TSP');
$this->db->from('tbl_instructor_info');
$this->db->where('email',$email);
$tsp = $this->db->get_compiled_select();
$this->db->select('ShortCode');
$this->db->from('tbl_tsp_info');
$this->db->where("`id`= ($tsp)", null, false);
$batchCode = $this->db->get_compiled_select();
$this->db->select('BatchID ');
$this->db->from('tbl_batch');
$this->db->where('round',7);
$this->db->like('BatchID', $batchCode);
$query = $this->db->get();
return $query->result();
}