supriyo roy
supriyo roy

Reputation: 1

Show rows with a column partially matching a given parameter

Suppose I have a table named testdb which has the following values:

|       Name       |    Phone   |ID |
|------------------|------------|---|
| supriyo roy      | 9038689236 | 2 |
| supriyo banerjee | 8013147879 | 3 |
| Alex ghosh       | 8985855665 | 4 |

Now, I am performing a search by the name and the input given is just "supriyo" (no last name given). The search result should show both the values:

|       Name       |    Phone   |ID |
|------------------|------------|---|
| supriyo roy      | 9038689236 | 2 |
| supriyo banerjee | 8013147879 | 3 |

Is this possible to achieve using MySQL and php?

Upvotes: 0

Views: 27

Answers (1)

Gurwinder Singh
Gurwinder Singh

Reputation: 39507

You are looking for LIKE:

select *
from your_table
where name like 'supriyo%';

Demo

Edit:

In php, use:

select *
from your_table
where name like '$name%';

Upvotes: 3

Related Questions