Jump to content
php.lv forumi

Paplašināt Mysql Search


Wuu

Recommended Posts

$result = mysql_query('select * from craft_db where skillkey1 like \'%'.$search.'%\' || name like \'%'.$search.'%\' order by skillval1 asc;');

Šādi mysql meklē $search... Bet ja piemēram iekš $search ir divi vardi kas adalīti ar +

piemēram zivis+traktors

Mans queri meklēs "zivis+traktors"

Bet es gribu lai meklē "ziviz" pectam "traktors"

Gala rezultātā lai es varētu meklēt uzreiz vairākus vārdus? Kā to labāk panākt?

Link to comment
Share on other sites

$result = mysql_query('select * from craft_db where skillkey1 like \'%'.$search.'%\' || name like \'%'.$search.'%\' order by skillval1 asc;');

 

Pieturoties pie Tavas meklēšanas metodes, dari tā:

sadali queriju vārdu masīvā ($search = explode(' ', $search)) un meklējamo queriju uzģenerē ciklā.

$result = mysql_query('select * from craft_db where skillkey1 like \'%'.$search[0].'%\' || name like \'%'.$search[1].'%\' ................  || name like \'%'.$search[count($search) - 1].'%\' order by skillval1 asc;');

Link to comment
Share on other sites

Papildinot, Kaitnieku (cerams, ka ar pēdiņām viss ok):

$search_mas = explode(' ',$search);

$vaicajums = 'SELECT * FROM craft_db WHERE skillkey1 LIKE "%' . implode('%" OR skillkey1 LIKE "%',$search_mas) . '%" OR name LIKE "%' . implode('%" OR name LIKE "%',$search_mas) . '%" ORDER BY skillval1 ASC';

 

[edit] drukas kļūda

Edited by Aleksejs
Link to comment
Share on other sites

×
×
  • Create New...