Wuu Posted December 17, 2008 Report Share 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? Link to comment Share on other sites More sharing options...
marcis Posted December 17, 2008 Report Share Posted December 17, 2008 str_replace("+","%",$str); Link to comment Share on other sites More sharing options...
Kaitnieks Posted December 18, 2008 Report Share 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;'); Link to comment Share on other sites More sharing options...
Aleksejs Posted December 18, 2008 Report Share 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 Link to comment Share on other sites More sharing options...
Klez Posted December 18, 2008 Report Share Posted December 18, 2008 Wuu, fulltext nevari izmantot ? Link to comment Share on other sites More sharing options...
Wuu Posted December 18, 2008 Author Report Share Posted December 18, 2008 Klez par ko tu runā? Paldies viss strādā! Link to comment Share on other sites More sharing options...
bubu Posted December 18, 2008 Report Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts