Curtis
Curtis

Reputation: 2704

find database rows that start with a character using PHP

How can I grab data from a database using an mySQL query which will get all rows that start with a certain string, for example;

$string = 'WS';

mysql_query("SELECT * FROM `table` WHERE `name` STARTS WITH '$string'");

something like the above

Upvotes: 0

Views: 110

Answers (2)

Let me see
Let me see

Reputation: 5094

SELECT * FROM `table` WHERE `name` LIKE 'WS%'

it will fetch only those values those have ws at the start...and not all values..try it once

Upvotes: 0

John Woo
John Woo

Reputation: 263723

you mean LIKE

SELECT * FROM `table` WHERE `name` LIKE 'WS%'

Upvotes: 6

Related Questions