PHP: How to search a cell if the word in it has a prefix?

Jangga

Junior Member
Joined
Aug 8, 2016
Messages
196
Reaction score
11
How to search a cell if the word in it has a prefix? Please, I'm stuck in doing this. My brain is just blocked here. I haven't seen such code. Help plsssssss...... I need ideas
 
select * from travis where citi='fixed_prefix%'
select * from travis where citi='new%'

select * from travis where citi='%fixed_subfix'
select * from travis where citi='%york'

select * from travis where citi='%fixed_middle_string%'
select * from travis where citi='%gor%'
 
Ahh, I thought you meant array data... my bad. Not had my Red Bull yet...

You can do it in two steps, first get the data with a query like this:

Code:
SELECT * from TableName Where ColumnName LIKE 'o hai%'

o hai = the prefix.

From this data then create a function with a for each loop and a preg_match to go through the returned results and find what you're looking for.
 
select * from travis where citi='fixed_prefix%'
select * from travis where citi='new%'

select * from travis where citi='%fixed_subfix'
select * from travis where citi='%york'

select * from travis where citi='%fixed_middle_string%'
select * from travis where citi='%gor%'

Since I want to select with two conditions will it work with and clause? E.G

select * from travis where user='$user' and citi='fixed_prefix%'


Please answer. Thanks in advance
 
Ahh, I thought you meant array data... my bad. Not had my Red Bull yet...

You can do it in two steps, first get the data with a query like this:

Code:
SELECT * from TableName Where ColumnName LIKE 'o hai%'

o hai = the prefix.

From this data then create a function with a for each loop and a preg_match to go through the returned results and find what you're looking for.

Since I want to select with two conditions will it work wwith AND clause? E.G

Code:
SELECT * from TableName Where ColumnName1='$user' AND ColumnName2 LIKE 'o hai%'

Thanks in advance
 
Yes, that will work fine.
 
Back
Top