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

React/ZMQ/Ratchet - Websocket server response
mysql prepared statement failing silently in a new machine
Text in here doc is not showing in multi line
Export Wordpress page to CSV from front end
SELECT SUM data rank and Resource id #9 error PHP
How to create this XML using PHP SimpleXMLElement?
Kirby CMS - add an image modified timestamp
Highlight Data After Success in jquery Ajax
Rewrite Magento catalog product view action
Combining Arrays elements due to similar values
An array and in_array
MySQL, SUM the column of a table view
Pulling data from Google Cal xml
How to explain this behaviour from DirectoryIterator?
Memcache session handler - what is the item that session_start() adds to the cache?
how can I adjust automatically a text in a CELL in Fpdf y php

Categories

HOME
oracle
spring-data
events
android-espresso
weblogic12c
yahoo-weather-api
xcode8.1
android-fragments
kendo-dropdown
transactions
greasemonkey
impala
mutation-testing
lda
outlook-restapi
trace32
twisted
c#-7.0
boomi
spring-ldap
coreldraw
stackexchange.redis
managed-c++
password-generator
npoi
ninject
sparkle
microprocessors
monitor
windowsiot
shapeless
adminer
wdk
mv
cloudera-quickstart-vm
sbjson
flipkart
swift2.3
viewmodel
image-registration
photoswipe
nonlinear-functions
entropy
punctuation
nivo-slider
clrs
dtd
dex
alertify
prefetch
perl-data-structures
maatwebsite-excel
deviare
openseadragon
powerpoint-2013
apple-configurator
android-async-http
django-redis
persistent-object-store
trust
univocity
enunciate
diawi
outlook.com
bayesglm
msgpack
fanotify
vdm-sl
com0com
fuseesb
mojo
loginview
xcode6.3.1
lumia-imaging-sdk
miglayout
sql-function
nodeload
meteorite
grails-2.3
jacob
cmath
handshake
daap
spark-view-engine
msinfo32
websphere-6.1
series-40
dropshadow
snackjs
grails-validation
django-pagination
firephp
processors
ning
motif
efs
chronic
rootkit
parentid

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App