Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2007, 05:23 AM   PM User | #1
student
Regular Coder

 
student's Avatar
 
Join Date: Jan 2007
Posts: 129
Thanks: 13
Thanked 0 Times in 0 Posts
student is an unknown quantity at this point
how to hide duplicate search results?

hello,
i have a PHP script directory with an MYSQL database and it has some duplicate records.
the directory has a search functionality and duplicate results are showing up in the search results.
i would like to hide these duplicate results ( but dont want to delete them ).
all the records have a 'unique item' and i would like to filter the results using this 'unique item' ( so that a record with the same 'unique item' should not appear more than once )

please inform me how to filter my search results to avoid duplicates.
i am new to PHP and MYSQL. please inform me the possible code.
thank you
student is offline   Reply With Quote
Old 01-14-2007, 02:31 PM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
you filter the results by not getting them in your sql statement in the first place.

please show some sample rows from your table as well as the output you would like to see from those rows and then show the sql query you are currently using.
guelphdad is offline   Reply With Quote
Old 01-14-2007, 08:19 PM   PM User | #3
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
From an email from the OP I will post their additional info here for all to see.

Code:
the table is:
cb_urls (
id int(11) NOT NULL auto_increment,
poll_id int(11) NOT NULL default '0',
link_count int(11) default '0',
popularityrank int(7) default '0',
destination varchar(12) NOT NULL default '',
title varchar(70) default NULL,
description text(400),
category varchar(100) default NULL,
PRIMARY KEY (id),
KEY category (category)
)";
there are some rows with the same 'destination', 'title', 'description', but with different
id, poll_id, popularityrank etc...
i would like to ensure that no row with the same 'destination' should repeat in the search results.
and order the results by popularity rank.

the query is:
PHP Code:
$sth mysql_query("SELECT * FROM cb_urls WHERE category='".addSlashes(strtolower($keywords))."' OR title LIKE '%".addSlashes(strtolower($keywords))."%' or description LIKE '%".addSlashes(strtolower($keywords))."%' GROUP BY popularityrank LIMIT $mdf_startbound, $perpage"); 
guelphdad is offline   Reply With Quote
Old 01-14-2007, 08:21 PM   PM User | #4
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
that shows your table but you also need to show some rows in the table and the output you want.

Show us where you have multiple destinations that are the same and then show us what row you want from those duplicates and explain the logic behind choosing that row and not one of the other rows with the same destination.
guelphdad is offline   Reply With Quote
Old 01-15-2007, 04:25 AM   PM User | #5
student
Regular Coder

 
student's Avatar
 
Join Date: Jan 2007
Posts: 129
Thanks: 13
Thanked 0 Times in 0 Posts
student is an unknown quantity at this point
hello,
thanks for your reply,
the example page is here:
http://downloadsonline.org/search.php?keywords=psp

destination field is hidden.
some rows have same destination, title, description but have different id, poll_id, popularityrank etc.

i would like to ensure that no row with the same destination or title or description repeat in the results.

can i make a query like this:

$sth = mysql_query("SELECT * FROM cb_urls WHERE destination != destination, category='".addSlashes(strtolower($keywords))."' OR title LIKE '%".addSlashes(strtolower($keywords))."%' OR keywd LIKE '%".addSlashes(strtolower($keywords))."%' or description LIKE '%".addSlashes(strtolower($keywords))."%' GROUP BY popularityrank LIMIT $mdf_startbound, $perpage");

thank you very much.

( yesterday i posted a pm with the reply because, i could not make a reply in the forum. even after waiting for a longtime, the hoverglass icon appeared without posting the reply. )
student is offline   Reply With Quote
Old 01-15-2007, 05:29 PM   PM User | #6
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
so do you think you could actually post some sample rows here, (not some obscure link that we are supposed to figure out what we are looking at), and within those four or five rows contain duplicate information that you want to weed out, and then show us of those four or five rows, which one you want as the only result returned and why?

here is an example:

black cow 1
black cow 2
black turtle 3
black cow 4

I want the black turtle returned because it is the only turtle, and I wante black cow 1 returned because it has the lowest numeric value of the three cows.

If you can do something like that it will most likely ensure that you can get assistance with your problem.

As for the posting problem, I'd say to hit stop and try to reload a web page when that happens.
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:08 AM.


Advertisement
Log in to turn off these ads.