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

PHP MYSQL JOIN error [duplicate]
Redirecting before executing commit()
display data together from 2 different SQL table
Developer forums protection, code on pages and mod_security
url_encode with WGET in PHP?
How to properly setup debug configurations in PhpStorm
How to select a query by a hashtag variable? [duplicate]
Convert datetime to GMT timestamp
PHP cURL, sometimes this error: The requested resource could not be loaded. libcurl returned the error: Connection timed out after 8001 milliseconds
Call to undefined method PDO::real_escape_string()
retrofit2 sending a PUT request method is wrong for PHP
PHP “global” variable not accessible in __construct
SQL Query If Statement?
Wordpress create account and copy user information to another database
Batch File executed via PHP runs all commands as background processes
Laravel jobs pushed to Amazon SQS but not processing

Categories

HOME
class
devexpress
iverilog
vsts-build
informatica
gallery
save
lc3
twitter-oauth
alljoyn
graphdb
django-rq
global-variables
word2vec
http-authentication
angular2-highcharts
workday
batch-rename
uislider
web-config-transform
introspection
webviewclient
php-5.3
location-services
rspec-rails
quickcheck
counting
nest
jfxtras
ng-repeat
microsoft-ui-automation
sbjson
grunt-contrib-watch
swfupload
hdiv
angular-datatables
coverage.py
raytracing
yoast
haar-classifier
spooler
julius-speech
git-tfs
sendinput
asihttprequest
docker-ucp
common-table-expression
section508
xcglogger
nothing
webvtt
gmaps.js
gawk
annotatorjs
gapi
mifos
streamwriter
jpda
mathml
android-sdcard
node-glob
uibinder
wif4.5
ioexception
outlook.com
google-maps-api-2
http.client
modern.ie
innerhtml
phonegap-facebook-plugin
jolie
rubber
zend-mail
producer
storing-data
object-code
ecos
stripe.net
preorder
jmenubar
san
xs
ofstream
ntlmv2
jsplitpane
msinfo32
coordinate
word-frequency
dropshadow
memory-pool
fbml
infopath-2007
will-paginate
startupscript
mongrel
chunking
ninject-interception
cassini
asdoc
data-retrieval
inversion
community-server
service-factory

Resources

Encrypt Message