Jump to content
php.lv forumi
Sign in to follow this  
Wuu

Paplašināt Mysql Search

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?

Share this post


Link to post
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;');

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

×
×
  • Create New...