php


Comparing first 4 characters from table and fetching data from database in codeigniter


I have two different tables as testimonial and pagetitles. While fetching the Pagetitles from database i need to compare first 4 characters if the 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

Related Links

Insert into table doesnt work
Doctrine2 ORM - Error using getResult
Tty to count the words from mysql results with php
Sql SELECT statement inside echo
Explode Textarea and Pass IN Select Statement
chat bubbles showing earlier in the chat iOS
Forgotten password page help [PHP/HTML]
File saving to server as invalid JSON
Footer div closing early on a single web page
Install curl to php on apache server
Laravel getting values from array for validation and storing in DB
Regex that match all js code but not the commented one
Can't use a file from Zend Frame Work
PHP while loop fill shop
Multiple Delete from table in PHP
Add Static php file but still can use wordpress template

Categories

HOME
qt
amazon-web-services
powerbi
memory
typelite
openxml
barcode-scanner
applescript
kivy
malware
azure-data-lake
facebook-android-sdk
tfs2010
stack-overflow
locationmanager
smartgwt
sonata
rpmbuild
bosun
multi-upload
amazon-sns
opentext
introspection
multi-dimensional-scaling
spreadsheetgear
basex
ccavenue
amazon-cloudtrail
tilemill
dotcms
sca
xmlunit
cloveretl
textmate2
runtimeexception
macports
xll
gitolite
oauth2-playground
vungle-ads
bit-shift
adblock
cordova-ios
gmaps.js
prefetch
fitbit
pbx
gapi
spring-mongo
dojo-build
qpixmap
accessibilityservice
hmisc
360-degrees
fantom
ssmtp
fat32
nanomsg
dos2unix
vs-unit-testing-framework
datagridcomboboxcolumn
producer
berkeley-db-xml
oracle-adf-mobile
webmethod
siena
coding-efficiency
two.js
forceclose
pageviews
application-blocks
saga
colon
xsd2code
codahale-metrics
lru
days
icenium
thejit
struts2-s2hibernate
liveconnect
servercontrol
ixmldomdocument
rawcontacts
datagridcolumn
webclient.uploaddata

Resources

Encrypt Message