0

I have a table that contains this data.

main_id main_name other_name
   1      aa aa     bb bb 
   1      aa aa     cc cc
   2      bb bb     aa aa
   2      bb bb     cc cc
   3      cc cc     aa aa
   3      cc cc     bb bb

I have a field where user will search by name, when user searches for name the query should get data like main_name and other_name.

What I have tried so far is:

select where main_name like $data_entered or other_name like $data_entered

the result of this gives me

main_id main_name other_name
   1      aa aa     cc cc
   3      cc cc     aa aa
   3      cc cc     bb bb

I need to include:

main_id main_name other_name
   1      aa aa     bb bb

id did a query like this:

select where main_name like $data_entered or (main_name like $data_entered or 
other_name like $data_entered)

but still can't get:

main_id main_name other_name
   1      aa aa     bb bb

Any help would be appreciated

By the way, I'm coding php, with codeigniter framework.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
derping
  • 15
  • 7
  • you have said that you want o/p like above that include Main name as "aa aa" but for which Dataentered you need o/p like this – Hardik Parmar Oct 30 '14 at 09:01
  • @HardikParmar every main_name has associated other_name, other_name could be more than 1. now when user search, result should include data_entered "like" main_name and main_name with all its other_name if there's other_name "like" data_entered" – derping Oct 30 '14 at 09:05
  • If poosible provide creation of table & insert query for the above code – Hardik Parmar Oct 30 '14 at 09:08
  • 1
    What is the value of $data_entered? Why do you need this specific row? `1 aa aa bb bb` – Perroquiet Oct 30 '14 at 09:39

0 Answers0