473,498 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to avoid displaying duplicates

1 New Member
I'm a first time poster and I would really appreciate any help. I'm working with a MySQL database using a Perl script to access the data and display as a web page. I'm stuck with one part. The database has repeated events in it. These events have the same title, but different dates/times. I would like to select all of the dates and times for each event, but only print each title one time. Right now I'm getting something like this:

Alef Ba--Arabic for preschoolers Sat, Oct 21 - 10:00 AM
Alef Ba--Arabic for preschoolers Sat, Oct 28 - 10:00 AM
Say it in Spanish Thu, Oct 19 - 9:30 AM
Say it in Spanish Thu, Oct 26 - 9:30 AM
Say it in Spanish Thu, Nov 2 - 9:30 AM
Your Child, Ready to Read Tue, Oct 17 - 10:00 AM
Your Child, Ready to Read Tue, Oct 24 - 10:00 AM

What I want is something like this:
Alef Ba--Arabic for preschoolers Sat, Oct 21 - 10:00 AM
Sat, Oct 28 - 10:00 AM
Say it in Spanish Thu, Oct 19 - 9:30 AM
Thu, Oct 26 - 9:30 AM
Thu, Nov 2 - 9:30 AM
Your Child, Ready to Read Tue, Oct 17 - 10:00 AM
Tue, Oct 24 - 10:00 AM


Thanks,
Paula
Oct 17 '06 #1
1 1649
miller
1,089 Recognized Expert Top Contributor
I'm going to run with two assumptions.
Assumption 1) Part of your problem is the fact that Date is included with the Title in the database
Assumption 2) You're already pulling the data sorted by Title.

Assuming this, you have only one problem, namely separating the title from the date. This can be accomplished with a simple regular expression. I'm going to also be assuming that your dates are of the form that you stated above, otherwise you might end up with problems.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. my @data = (
  4.     'Alef Ba--Arabic for preschoolers Sat, Oct 21 - 10:00 AM',
  5.     'Alef Ba--Arabic for preschoolers Sat, Oct 28 - 10:00 AM',
  6.     'Say it in Spanish Thu, Oct 19 - 9:30 AM',
  7.     'Say it in Spanish Thu, Oct 26 - 9:30 AM',
  8.     'Say it in Spanish Thu, Nov 2 - 9:30 AM',
  9.     'Your Child, Ready to Read Tue, Oct 17 - 10:00 AM',
  10.     'Your Child, Ready to Read Tue, Oct 24 - 10:00 AM',
  11. );
  12.  
  13. my $lastTitle = '';
  14. foreach my $record (@data) {
  15.     $record =~ s{^(.*) (\w*,.*)$}{$1};
  16.     my $date = $2;
  17.  
  18.     if ($lastTitle ne $record) {
  19.         $lastTitle = $record;
  20.         print "$record $date\n";
  21.     } else {
  22.         print "$date\n";
  23.     }
  24. }
  25.  
  26. 1;
  27.  
  28. __END__
  29.  
Please note that another good way to test for duplicates is to use a hash. Because I was assuming the data was already in order though, it more efficient memory wise to use a scalar to simply keep track of the last title seen instead of all the titles seen.
Oct 18 '06 #2

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

Similar topics

8
3257
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
6
2372
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
19
2859
by: Charles Law | last post by:
Take a solution with a project hierarchy along the lines of an n-tier system, so that we have a data layer, business layer and presentation layer. The presentation layer is coupled to the business...
3
2161
by: AK | last post by:
Hi Our product uses MS-SQL Server 2000. One of our customer has 10 installations with each installation stroring data in its own database. Now the customer wants to consolidate these databases...
6
6502
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST...
1
4316
by: charliej2001 | last post by:
Hi all My access database has import/export capabiltiy of contact details between outlook. The database is getting big now (1000+ contacts) and so are the outlook address books that have the...
3
2819
by: ryan.paquette | last post by:
In the table there are 2 fields in which I wish to limit (i.e. No Duplicates) Although I do not want to limit them to "No Duplicates" separately. I need them to be limited to "No Duplicates" as...
2
2707
kcdoell
by: kcdoell | last post by:
Hello: I have three unbound text boxes in which I have the following calculations in the control source of each box: FCST Total; =Nz(DSum("","ReQryForecast"," >= 75"),0) Budget Total; ...
1
2129
by: tskmjk55 | last post by:
Recently, I have a requirement to develop a vb.net application wherein the input excel sheet data which has an average of 5000 records should be checked for Internal duplicates (duplicates within the...
3
25047
Thekid
by: Thekid | last post by:
I'm trying to figure out a way to find if there are duplicates in an array. My idea was to take the array as 'a' and make a second array as 'b' and remove the duplicates from 'b' using 'set' and then...
0
7125
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,...
0
7203
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...
1
6885
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...
0
5462
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,...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
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...
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.