1

I would like to select rows which start with the word s but I am getting other results as well. I have rows red socks, blue sweater, skirt.... in the table and when I do the select as below I end up with the above result. I am guessing this is because the red socks contain s on the second word, so how can I just select skirt?

 $pr = 's%' 

$stmt = $db->prepare("SELECT * FROM table where product like ?");
$stmt->bind_param('s', $pr);
$stmt->execute(); 

rows returned

  skirt
  red socks
  blue sweater

I only need skirt

HoldOffHunger
  • 15,349
  • 8
  • 79
  • 115
user2666310
  • 103
  • 2
  • 15

2 Answers2

0
SELECT * FROM table where product like 's%'

You should look at this:

http://www.tutorialspoint.com/mysql/mysql-like-clause.htm

ddagsan
  • 1,668
  • 18
  • 20
0

You are missing ; after $pr = 's'. Try:

$pr = 's'; 
$stmt = $db->prepare("SELECT * FROM table where product like CONCAT(?, '%')");
$stmt->bind_param('s', $pr);
$stmt->execute();
Lucas Henrique
  • 1,407
  • 1
  • 11
  • 15