Twistedweb123 Posted March 6, 2011 Share Posted March 6, 2011 I am working on a poject, where the search functions doesnt work as the user wishes. The coding is technically correct, but the idea behind it is wrong. Basically at the moment, the script receives this: thesite.com/search.php?q=xxxx&Submit=Search The search script then runs a database query to search the tag coloumn, looking for like $q. This would work, however the structure of the coloumn is tag1, tag2, tag3, tag4. So my resolutions is this so far: I explode the $q variable, via the + (if you search more than one term "thesite.com/search.php?q=search+stuff&Submit=Search" I then count the elements in the array and write the database function accordingly $var = @$_GET['q'] ; $trimmed = trim($var); $searchpieces = explode("+", $trimmed); $dbquery=""; $count = count($searchpieces); for ($i = 0; $i < $count; $i++) { if($i == 0){$dbquery.="tags = $searchpieces[$i]";} elseif($i > 0){$dbquery.=" OR tags = $searchpieces[$i]";} } So my database query is $sql = "select * from gallery where $dbquery order by date DESC " . $limit; so my question is this.. how to i eplode the tags database coloumn, so my datase query an look at each tag fro "tag1, tag2, tag3" as "tag1" "tag2" "tag3" I am not even sure if this is possible, but its the system that is already in place. The problem with the current system, is because the pictures have alot of tags and the database query is $like $q, it just shows all images in the database as the result Quote Link to comment https://forums.phpfreaks.com/topic/229728-searching-tags/ Share on other sites More sharing options...
.josh Posted March 6, 2011 Share Posted March 6, 2011 $var = @$_GET['q'] ; $trimmed = trim($var); $searchpieces = explode("+", $trimmed); $searchpieces = "'" . implode("','",$searchpieces) . "'"; $sql = "select * from gallery where tags IN($searchpieces) order by date DESC " . $limit; Quote Link to comment https://forums.phpfreaks.com/topic/229728-searching-tags/#findComment-1183412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.