Jump to content

Archived

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

dannel77

Search multiple fields..

Recommended Posts

Hi,

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

Share this post


Link to post
Share on other sites
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%'

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.