I have two different tables as testimonial and pagetitles. While fetching the Pagetitles from database. I need to compare first 4 characters if both matches then I should get the data.
function getpagetitle($id)
{
$this->db->select('P.*,T.testimonial_name');
$this->db->from('pagetitle AS P');
$this->db->join('testimonials AS T','SUBSTR(T.testimonial_name, 4) = SUBSTR(P.page_title, 4)','INNER');
$this->db->where(array('P.page_title'=>$id));
$q=$this->db->get();
//var_dump($this->db->last_query());
//print_r($q->num_rows());
if($q->num_rows()>0)
{
$output = $q->result();
return $output[0];
}
else
{
return false;
}
}
Database tables
testimonials:
+----------------+-------------------+-------------+
| testimonial_id | testimonial_name | client_name |
+----------------+-------------------+-------------+
| 1 | testimonial | abc |
| 2 | testimonial | def |
+----------------+-------------------+-------------+
Pagetitle
+--------------+-------------+
| pagetitle_id | pagetitle |
+--------------+-------------+
| 1 | testimonial |
| 2 | career |
+--------------+-------------+
i think you have to use if then statement in mysql , so if we want to change your query , it must be something like this :
select P.*,T.testimonial_name from pagetitle AS P , testimonials as T (
select IF 'SUBSTR(T.testimonial_name, 4) = SUBSTR(P.page_title, 4)'
where P.page_title>5
)
i dont test it , but i think it must be true
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