Jump to content


Search multiple fields..

  • Please log in to reply
1 reply to this topic

#1 dannel77

  • Members
  • PipPip
  • Member
  • 22 posts

Posted 10 September 2006 - 02:14 PM


I need help modifying this script so that it becomes possible to search multiple fields instead
of just one field. As it is now I can search for one specific word (within a table row) but if I
try and make a search for 2 words *with another word in between* it doesn't work. Hope I
make som sense.. :P

$searchstring = trim($searchstring);// remove leading and trailing blanks

// Nu bestämmer vi antal per sida och kollar upp totala antalet
$limit = 30; // Antal per sida
$where = "$chose LIKE '%$searchstring%' OR item LIKE '%$searchstring%' OR code_no LIKE '%$searchstring%'";

$result = @mysql_query("SELECT COUNT(*) FROM products WHERE item LIKE '%$searchstring%' OR code_no LIKE '%$searchstring%'")
or die("Error fetching number in DB<br>".mysql_error());
$numrows = @mysql_result($result, 0); // Antal i databasen

#2 onlyican

  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 10 September 2006 - 02:21 PM

Try this
if the string to search for is
"Search String";
then replace the space with a %
so the query would look like
SELECT * FROM tablename WHERE fieldname LIKE '%search%string%'
Tell me the problem, I will try tell you the solution

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users