Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.