473,385 Members | 1,353 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,385 software developers and data experts.

How do I get rid of these duplicate rows?

290 100+
Does anyone have any advice about how I
can get these duplicates rows out of my results array ?

If you look here:

Clickbank Super Analyzer

Then just hit the Analyse Clickbank Now button
you will see these all have double entries:

ID: AFFSUPER
ID: COHYPNOSIS
ID: MAVERICK66

I want to just show one of them (the first one)

This is the script that outputs that list:
(this is just one if out of about ten)
Expand|Select|Wrap|Line Numbers
  1. if($Db_recurr == "r"){            
  2.        $sql = "SELECT * FROM clickbank WHERE (title LIKE '%$Db_search%' || descrip LIKE '%$Db_search%' )
  3.     AND pop > '$Db_pop_min' AND pop < '$Db_pop_max' AND grav > '$Db_grav_min' AND grav < '$Db_grav_max' 
  4.     AND percent > '$Db_sale_pc_min' AND recurr = 't' AND totearn > '$Db_earn_min' AND cat = '$Dpcat' 
  5.     ORDER BY $Db_sort1 DESC, $Db_sort2 DESC ";
  6.     } // end if
  7.  
  8. $result = mysql_query($sql)
  9.     or die("could not execute SELECT Clickbank". mysql_error());  
  10. $num = mysql_num_rows($result);
  11.  $Rctr = 1;
  12.  while($row = mysql_fetch_assoc($result)){
  13.         extract($row);
  14.     $extr = $totearn-$earn;                
  15.     $disp1 = "<b>$Rctr) $cat</b><br>$title, <b>ID: $id</b><br>";
  16.         $disp2 = "$descrip<br>";
  17.     $disp3 = "<b>$/sale: $earn, +/mth: $rebill, Pop: $pop, Gravity: $grav, Comm%: $comm, Refers: $refer, Total Earn: $totearn</b>";
  18.     echo "<div style=\"width: 800px; text-align: left;\">
  19.         <span>$disp1</span>
  20.     <span>$disp2</span>
  21.     <span>$disp3</span>
  22.     <br><br>
  23.     </div>";
  24. if($Rctr >= $Db_resp)
  25. { exit();        
  26. } // end if
  27.  $Rctr = $Rctr+1;     
  28. } // end while        
Thanks for any help
Dec 3 '09 #1
10 2526
Dormilich
8,658 Expert Mod 8TB
some possibilities:
1) don’t loop over the result set.
2) limit your sql query (SELECT … LIMIT 1)
Dec 3 '09 #2
jeddiki
290 100+
Thanks,

I am sure you meant well, but did you
take a look at the list that script produces ?
(it is only two clicks away)

I need to loop through the result so that I can
get all of the results, I just do not want to get
the duplicate ones.

Please take a look at the output via the
link, it shows exactly what I mean.

thanks
Dec 3 '09 #3
Dormilich
8,658 Expert Mod 8TB
how does it come that the duplicates have different categories then? you may try SELECT DISTINCT* (SELECT DISTINCTROW) but I’m not really sure, whether it works for you.

* - at about one fifth of the page
Dec 3 '09 #4
jeddiki
290 100+
Thanks again for your reply.

how does it come that the duplicates have different categories then?
This happens because clickbank allows product sellers to place their products into TWO categories if they want to. That is why everything is the same except the category field.

If someone just searchs within one category then there will be no duplicates in the output list, but if you search on ALL categories, you get a lot of duplicates.

What I want to do is give an option to exclude duplicates from the listing. In that case just the first occurance will get listed.

Hope that makes sense :-)

I looked at SELECT DISTINCT but I need to focus the distinctivenes on just the ID code because within the row there are many fields that are OK to be duplicated - the category field is an obvious one.

For that reason, I started looking at the output array - hoping that maybe I could use the UNIQUE filter somehow. But I can not get it working.

Any ideas ?
Dec 4 '09 #5
Dormilich
8,658 Expert Mod 8TB
but I need to focus the distinctivenes on just the ID code because within the row there are many fields that are OK to be duplicated
then fetch only the ID (there you can use SELECT DISTINCT) and get the entries in another request* (at least that’s what I would do)

* - Prepared Statements come to mind
Dec 4 '09 #6
MrMancunian
569 Expert 512MB
I am sure you meant well, but did you
take a look at the list that script produces ?
(it is only two clicks away)
...
Please take a look at the output via the
link, it shows exactly what I mean.
Excuse me?! Dormilich makes two suggestions, as per your request and this is the way you answer him? I must say, I'm surprised that he even bothered to answer you after this post, something that earns him credits. I suggest that you show some respect for someone who is answering your post!

Steven
Dec 4 '09 #7
Dormilich
8,658 Expert Mod 8TB
let’s put it this way, the description in the post didn’t match the situation exactly enough and I really didn’t use the link.

and I’ve read worse…
Dec 4 '09 #8
MrMancunian
569 Expert 512MB
So even if you didn't use the link, I still find his reply very rude.
Dec 4 '09 #9
jeddiki
290 100+
Sorry to upset you MrMancunian,

I certainly never meant any disrespect, I very much appreciate the help that Dormilich gives and I always thank for input given. The answer from D did suggest that the output list hadn't been seen, that is all I meant.

-----------------------------------------------------------------------------------------

then fetch only the ID (there you can use SELECT DISTINCT) and get the entries in another request* (at least that’s what I would do)
Not quite sure how to do a doubled-up query !

This is one of my queries:

Expand|Select|Wrap|Line Numbers
  1. if($Db_recurr == "n"){            
  2. $sql = "SELECT * FROM clickbank WHERE (title LIKE '%$Db_search%' || descrip LIKE '%$Db_search%' )
  3. AND pop > '$Db_pop_min' AND pop < '$Db_pop_max' AND grav > '$Db_grav_min' AND grav < '$Db_grav_max' 
  4. AND percent > '$Db_sale_pc_min' AND recurr = 'f' AND totearn > '$Db_earn_min' AND cat = '$Dpcat' 
  5. ORDER BY $Db_sort1 DESC, $Db_sort2 DESC ";
  6. } // end if
So how would I fit in:

Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT  DISTINCT id FROM clickbank WHERE ???
Any explanation much appreciated.
Dec 4 '09 #10
dlite922
1,584 Expert 1GB
You can also use GROUP BY.

To answer your last post, you used the * (all fields), so I don't know what the fields are in clickbank table, but you can group by the one that's duplicate... would this be "title"? if so,

put GROUP BY title at the end of your query.




Dan
Dec 4 '09 #11

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

Similar topics

2
by: John Steen | last post by:
This is probably a silly question to most of you, but I'm in the process of splitting off years from a large DB to several smaller ones. Some of the existing smaller DBs already have most of the...
2
by: Richard | last post by:
Hi Everyone, I have a table in which their is record which is exactly same. I want to delete all the duplicate keeping ony 1 record in a table. Example Table A Empid currentmonth ...
3
by: dan graziano | last post by:
Hi, How do you suggest is the best way to check for duplicate rows in an access table. And once one knows if there are duplicates, to remove all but one. In my access table, there are 5...
1
by: Asha | last post by:
greetings, does anyone have any idea how to delete duplicate rows in a dataset gracefully (the fast and easy way)
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
2
by: Rich | last post by:
Hello, I am just checking if there is a property or technique for displaying or retrieving from a dataTable the top 1 row(s) for rows containing duplicate keys (IDs). I have to pull data from a...
3
by: rajeshkrsingh | last post by:
Hi friends, Step1- create table duplicate ( intId int, varName varchar(50) ) insert into duplicate(intId,varName) values(1,'rajesh') insert into duplicate(intId,varName) values(2,'raj12')...
5
jamesd0142
by: jamesd0142 | last post by:
My manager and I where looking at some complex code to eliminate duplicate records in a database table. then it hit me how its done easily... so i thought i'd share it... In English:...
1
by: rfeio | last post by:
Hi! I have a table with several rows, some of which I need to duplicate. The fields of table1 are field1, field2, field3 and field4. Field1 is automatically incremented, field2 will serve as a...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.