Wuu Posted December 17, 2008 Report Posted December 17, 2008 $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?
Kaitnieks Posted December 18, 2008 Report Posted December 18, 2008 $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;');
Aleksejs Posted December 18, 2008 Report Posted December 18, 2008 (edited) 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 December 18, 2008 by Aleksejs
Wuu Posted December 18, 2008 Author Report Posted December 18, 2008 Klez par ko tu runā? Paldies viss strādā!
bubu Posted December 18, 2008 Report Posted December 18, 2008 fulltext ir daudz advancētāka meklēšana par parastu LIKE %...%. Gan iespēju ziņā, gan arī performances: http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html
Recommended Posts