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

How do I use usort() on a multidimensional array? [duplicate]
Check all value of specific index in array object is Null or not?
Create session before access to page
SonataUserBundle override user profile
XML parsing in PHP not capturing one variable
input type file Isset returning false even when set
Check if certain HTTP header was defined already
Is $this->uri->segment(3) secure in Codeigniter
How to check if an error code matches error_reporting
How to check if a stripe standalone account is verified?
SCRAM-SHA-1 auth by PHP
php version_compare() fails on localhost, runs on server
Using utf-8 in php and loading file (require_once) gives strange char
delete_others_posts capability as false not working
Which result type is better for soap result
PDO not throwing exception with unbound parameters (and no variables in query)

Categories

HOME
firebase
openxml
qc
couchdb
concurrency
hdfs
embedded-resource
websocket
linker
ag-grid
phpseclib
azure-graph-api
slide
graphdb
vimeo
mailmerge
multi-step
live-streaming
outlook-restapi
sql-injection
supervisord
closures
exe
significance
kamailio
intel
pyopencl
mod-wsgi
environment
managed-c++
adapter
envoy
google-play-developer-api
apptentive
dreamfactory
pdfnet
macports
httphandler
virtual-memory
julius-speech
nusoap
openstack-glance
solr-query-syntax
watir-webdriver
asp.net-web-api-routing
word-2007
wikimapia
lvalue
kendo-editor
clp
p6spy
declarative
groovyfx
unsigned
swiffy
gridbaglayout
webgrind
msgpack
directx-9
green-threads
darwin
karma-coverage
wicked-gem
deque
nhibernate-criteria
fasterxml
adwords-apiv201402
commenting
nosql-aggregation
django-sites
virtual-channel
indesign-server
unicoins
eager-loading
aero
chefspec
significant-digits
nsmutablestring
arrow
telerik-ajax
flymake
infopath-2007
litespeed
firefly-mv
zend-test
browser-based
dm
version-control-migration
prism-2
acceleration
isapi-redirect
regioninfo
synthesizer

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile