Irishgirl
Irishgirl

Reputation: 751

php mysql one table two field separate search result

I've mysql one table with two field object1 and object2. A separate query search result by typing in ID on input form only any ID that match object1 with 222 and 333 will return a query result of a same row of the ID.

The same for object2 by typing ID that match with object2 with 444 and 999 will return a query result of a same row of the ID.

For example, type in 12345 in input form and a result will show Joe Long object1 (instead of 222)

Can anyone think of sql and php please?

For example if I search by ID 12345 then I want get result as Joe Long, object1.

 +-----------------------------------------------------------------+
 | ID        | firstName   | lastName | object1 | object2 | sortID |
 +-----------------------------------------------------------------+
 | 12345     | Joe         | Long     |  222    |    444  |   66   |
 | 12346     | John        | Higgins  |  222    |    444  |   66   |
 | 12347     | David       | Crowe    |  333    |    444  |   66   |
 | 12348     | Denise      | Jacob    |  333    |    999  |   77   |
 | 12349     | George      | Jacob    |  333    |    999  |   77   |
 | 12350     | Iain        | Jacob    |  111    |    444  |   66   |
 | 12351     | Kevin       | Dalglish |  888    |    555  |   77   |
 | 12352     | Christina   | Brown    |  888    |    555  |   77   |
 | 12353     | Jean        | Scholes  |  888    |    555  |   66   |
 | 12354     | Angela      | Scholes  |  333    |    555  |   77   |
 | 12355     | Ellie       | Scholes  |  333    |    555  |   77   |
 +-----------------------------------------------------------------+

Upvotes: 0

Views: 220

Answers (1)

Seabass
Seabass

Reputation: 1973

Probably something like:

select *
from `table`
where object1 like '%query%' or object2 like '%query%'
group by ID 
order by sortID asc

Upvotes: 1

Related Questions