Jump to content

Searching tags


Twistedweb123

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/229728-searching-tags/
Share on other sites

Archived

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

×
×
  • Create New...

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.