Jump to content

Search Function


Gatsu

Recommended Posts

Hello I've got a little website where people can place adds and now I'm stuck at the "search" part.I've got 4 options when searching: voc, lvl, server, priceNow I would like to know if this is possible to use or if you have any suggestions on how I can do it.

$voc = $_REQUEST['voc'];$lvl = $_REQUEST['lvl'];$server = $_REQUEST['server'];$price = $_REQUEST['price'];if(($voc=='All') && ($lvl=='All') && ($server=='All') && ($price=='All')) {$result = mysql_query("SELECT * FROM addacc WHERE gransk=1 ORDER BY id desc LIMIT $offset, $rowsperpage");}else{$result = mysql_query("SELECT * FROM addacc WHERE gransk=1 MATCH (voc,voc1,voc2,voc3,lvl,lvl1,lvl2,lvl3,world,world1,world2,world3,price) AGAINST ('+$voc +$lvl +$server +$price' IN BOOLEAN MODE) ORDER BY id desc LIMIT $offset, $rowsperpage");}

Thanks for reading!

Link to comment
Share on other sites

I'm not sure specifically what your question is, but yes it's possible to use MATCH..AGAINST to search in a table. Your code as written will either return all rows if the fields were all "All", or if at least one field was not "All" then it will search in all of the given columns or indexes for any of the entered text. You can have PHP print that query out if you want to see what the final result looks like.

Link to comment
Share on other sites

Thanks for reply.Ok so im checking what it prints and its working.I'm getting:

SELECT * FROM addacc WHERE gransk=1 MATCH (voc,voc1,voc2,voc3,lvl,lvl1,lvl2,lvl3,world,world1,world2,world3,price) AGAINST ('+All +All +Refugia +All' IN BOOLEAN MODE) ORDER BY id desc LIMIT 0, 20

when choosing world Refugia.But then on the page I get this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in G:\xampp\htdocs\accs.php on line 291
291:
while ($add = mysql_fetch_array($result, MYSQL_BOTH)) {

This means that there is something wrong with my query?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...