1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Programming' started by Jangga, Mar 8, 2017.

  1. Jangga

    Jangga Junior Member

    Joined:
    Aug 8, 2016
    Messages:
    119
    Likes Received:
    4
    Gender:
    Male
    Occupation:
    Freelancer: A reWriter
    Location:
    Africa
    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
     
  2. I know SEO

    I know SEO Marketplace Mod Moderator

    Joined:
    Nov 29, 2012
    Messages:
    15,724
    Likes Received:
    6,119
  3. Jangga

    Jangga Junior Member

    Joined:
    Aug 8, 2016
    Messages:
    119
    Likes Received:
    4
    Gender:
    Male
    Occupation:
    Freelancer: A reWriter
    Location:
    Africa
    Thanks, but
    I don't know how to use it in a select query
    mysql_query("select * from travis where citi='preg_match(condition here)'");

    That won't work. Please, help
     
  4. handmadebots

    handmadebots Senior Member

    Joined:
    Nov 8, 2012
    Messages:
    960
    Likes Received:
    216
    Home Page:
    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%'
     
    • Thanks Thanks x 1
  5. I know SEO

    I know SEO Marketplace Mod Moderator

    Joined:
    Nov 29, 2012
    Messages:
    15,724
    Likes Received:
    6,119
    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.
     
    • Thanks Thanks x 1
  6. Jangga

    Jangga Junior Member

    Joined:
    Aug 8, 2016
    Messages:
    119
    Likes Received:
    4
    Gender:
    Male
    Occupation:
    Freelancer: A reWriter
    Location:
    Africa
    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
     
  7. Jangga

    Jangga Junior Member

    Joined:
    Aug 8, 2016
    Messages:
    119
    Likes Received:
    4
    Gender:
    Male
    Occupation:
    Freelancer: A reWriter
    Location:
    Africa
    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
     
  8. I know SEO

    I know SEO Marketplace Mod Moderator

    Joined:
    Nov 29, 2012
    Messages:
    15,724
    Likes Received:
    6,119
    Yes, that will work fine.
     
    • Thanks Thanks x 1
  9. Jangga

    Jangga Junior Member

    Joined:
    Aug 8, 2016
    Messages:
    119
    Likes Received:
    4
    Gender:
    Male
    Occupation:
    Freelancer: A reWriter
    Location:
    Africa
    Thanks man