473,378 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Prevent search of same word twice

17
Im going totally crazy over this.
Im right now building a verry small solution for searching a mysql-database for up to five keywords.
Every file in the database has 2 or more keywords wich the searchengine compares its keywords to.

There is a great problem though, i get many results twise.
EXAMPLE:

Search for: cow and dog

"dog" will return all files with the keyword dog and so will cow with the keyword cow. But when a file contains both the keywords dog and cow it is going to be listed once for each of the searched words.

Sorry, i know it sounds a little confusing, but see for your self.

Expand|Select|Wrap|Line Numbers
  1. $search=$_POST["search"];
  2.  
  3. list($s1, $s2, $s3, $s4, $s5) = split('[+ ]', $search);
  4.  
  5. $searcharray = array($s1, $s2, $s3, $s4, $s5);
  6.  
  7.  echo "<table>";
  8. foreach($searcharray as $var)
  9. {
  10.     if(isset($var))
  11.     {
  12.  
  13.          $result = mysql_query("SELECT * FROM $dbtable WHERE keyword LIKE '%$var%'");
  14.  
  15.  
  16.  
  17.         while ($row = mysql_fetch_assoc($result))
  18.         {    
  19.  
  20.  
  21.            $id=$row["id"];
  22.            $name=$row["name"];
  23.            $type=$row["type"];
  24.            $size=$row["size"];
  25.            $keyword=$row["keyword"];
  26.  
  27.  
  28.  
  29.            ?>
  30.           <tr><td><a href="download.php?id=<?php echo $id;?>"><?php echo $name;?></a><br />
  31.               <?php
  32.  
  33.            echo "<span class=style2>keywords: $keyword<br></span><br> ";
  34.            echo "</td></tr>";
  35.  
  36.         }
  37.  
  38.     }
  39. }
  40.  
(there is alot more code but it does not really have anything to do with the problem)

I thought i could use an array to store all the names of the files that have already been listed and then compare that list to every new result of the search,
but somehow i cant really get it to work out the right way.

Can someone please give me a push in a right direction?
Aug 26 '07 #1
3 1534
pbmods
5,821 Expert 4TB
Heya, Moezzie.

Try using SELECT DISTINCT.
Aug 26 '07 #2
Moezzie
17
Thank you pbmods, that worked just perfectly.

I think im going to continue doing some work with php/mysql, its really fun stuff and has alot of great features.
I'l be back! ;)
Aug 26 '07 #3
pbmods
5,821 Expert 4TB
Heya, Moezzie.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 26 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: cassandra.flowers | last post by:
Hi, I have another string handling question for the group, since you have all been so helpful in the past. Thank you. Basically, I want to do something really simple: Search a main...
3
by: RiceGuy | last post by:
Hi! I'm looking for ideas on what would the best approach to design a search system for a RSS feeds. I will have some 50 RSS feeds (all RSS 2.0 compliant) stored locally on the web server. Now I'm...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
7
by: Douglas | last post by:
I have a frontend and backend database , program.mde and data.mdb on a client PC. How do i prevent them launching the program.mde more than once on a single PC? Somtimes they minizmise the program...
1
by: bradley | last post by:
I have an \upload folder beneath the web root where I have MS Word and other documents that I would prefer not be available to the public. How can I configure web.config to prevent these files from...
3
by: Russell | last post by:
Hey, ok i have numerous tables to search through for a 'site search'. some of the searchble fields have html embeded within so after some quick referencing, saw I can use the regExp function...
7
by: e_matthes | last post by:
Hello everyone, I've read enough about email validation to know that the only real validation is having a user respond to a confirmation message you've sent them. However, I want to store the...
6
by: Arthur Dent | last post by:
Anyone know, in VB.NET (2005) how to prevent duplicate occurrences of the same event handler on an event? e.g... I have some object which raises an event, and some other class which consumes...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.