2

Content of entire pos column is home01+home03 or home02+home04.
I need to select rows where pos contains home01.

$pos = 'home01';
$stmt = $db->query("select * from banners where pos contains '" . $pos . "'");

Nothing is selected.
Also I need to avoid LIKE statement because of large table.
Any help?

qadenza
  • 9,025
  • 18
  • 73
  • 126
  • `where left(pos,6) = '.$pos."'"` or you could pass in length of pos as an attribute. – xQbert Apr 24 '17 at 14:24
  • @xQbert, content is dinamically changed - is not always the same position of a string. – qadenza Apr 24 '17 at 14:29
  • http://stackoverflow.com/questions/2602252/mysql-query-string-contains or use regular expression... looking for example – xQbert Apr 24 '17 at 14:31

2 Answers2

2

You can use match againts

ALTER TABLE table_name ADD FULLTEXT(pos);

SELECT * FROM banners MATCH(pos) AGAINST('+$pos+');
Nishant Nair
  • 1,999
  • 1
  • 13
  • 18
0

use this query

select * from banners where pos like'%" . $pos . "'";

this query return all row where first match home01

Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43