473,670 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prevent search of same word twice

17 New Member
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 1553
pbmods
5,821 Recognized Expert Expert
Heya, Moezzie.

Try using SELECT DISTINCT.
Aug 26 '07 #2
Moezzie
17 New Member
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 Recognized Expert Expert
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
6723
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 string for a substring, then count how many times the
3
2154
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 wondering what would the best method to allow searching of these RSS files. Since the search will cater to multiple users the search system has to be robust and efficient. Some ideas that I have for the RSS search system are: 1. Store all RSS...
14
4622
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 eBay, Yahoo and others. This is what she wants my program to be able to do: (try this test at different websites just for fun). At eBay: - enter the word 'television' in a search field à you will get 2155 items.
20
2880
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
7300
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 and dont see it and startup an new copy. At a later stage I want this database to be multiuser, on a network , so i dont want to limit the database to one user only, just one program lauch per PC
1
1389
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 turning up in a search engine list and prevent an unauthenticated user from typing in the url. This is a hosted site, and I can use forms or windows authentication.
3
2019
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 to strip out all the HTML leaving only the raw text. (done and works a treat) My issue is:
7
3046
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 address temporarily, so I want to make sure what is entered is safe to work with. I have a basic understanding of regexps, so I could write one that checks for a simple format like: something followed by @ followed by something followed by .....
6
4095
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 them. So in essence what I want to do is something like this in the consumer class... If Not objEventSource.SomeEvent.Handlers.Contains(AddressOf me.EventHandler) Then _ AddHandler objEventSource.SomeEvent, AddressOf me.EventHandler
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8817
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8663
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7423
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5687
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4396
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.