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. -
$search=$_POST["search"];
-
-
list($s1, $s2, $s3, $s4, $s5) = split('[+ ]', $search);
-
-
$searcharray = array($s1, $s2, $s3, $s4, $s5);
-
-
echo "<table>";
-
foreach($searcharray as $var)
-
{
-
if(isset($var))
-
{
-
-
$result = mysql_query("SELECT * FROM $dbtable WHERE keyword LIKE '%$var%'");
-
-
-
-
while ($row = mysql_fetch_assoc($result))
-
{
-
-
-
$id=$row["id"];
-
$name=$row["name"];
-
$type=$row["type"];
-
$size=$row["size"];
-
$keyword=$row["keyword"];
-
-
-
-
?>
-
<tr><td><a href="download.php?id=<?php echo $id;?>"><?php echo $name;?></a><br />
-
<?php
-
-
echo "<span class=style2>keywords: $keyword<br></span><br> ";
-
echo "</td></tr>";
-
-
}
-
-
}
-
}
-
(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?
3 1553 pbmods 5,821
Recognized Expert Expert
Heya, Moezzie.
Try using SELECT DISTINCT.
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! ;)
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 :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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.
|
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
};
|
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
| |
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.
|
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:
|
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
.....
|
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
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |