473,834 Members | 1,464 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 1666
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
3313
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 data in many of the fields so I paste in the same values of the previous record and then edit what needs edited in the new record saving much retyping of the same data. Doing this however creates the definite possibility of creating a duplicate...
6
2409
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 Qty Invoice# Item Supplier Status POReceivedDate 570133 03/09/2004 50 0 DMEDIUM L0010 PENDING 03/09/2004 570133 03/09/2004 50 0 DMEDIUM L0010 PENDING 03/09/2004 570133 03/09/2004 50 0 DMEDIUM L0010 PENDING 03/09/2004
19
2904
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 layer, and the business layer is coupled to the data layer. So far so good. Suppose the data layer raises an event, and it passes Me (the sender) as an object, and e (MyEventArgs, a descendent of EventArgs) to the layer above (the business...
3
2177
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 into one and we already have plan for that by consolidating one DB at a time. But first they want to find how many unique or duplicate entries they have across all the 10 databases Assumptions:
6
6530
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 data will be resubmitted), the previously submitted record is sumbitted again, and a duplicate record is inserted into the table. In PHP I would have avoided this by submitting the form to a processing page, which would then automatically...
1
4350
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 contacts info in them. When I export contacts from access to outlook, it takes a long time because there are so many contacts in the Outlook address book, and it is checking all of these against the contacts coming in, so as to avoid duplicates....
3
2855
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 if they were one field. The 2 fields are "Employee_Name" & "Training_Course". *(There is another table for Employees & another for Training Courses, both of which are related to this table.)
2
2729
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; =Nz(DSum("","QryBudget_Sum"),0) FCST vs. Budget; =(Nz(Forms!Forecast!SumGWP,0)-Nz(Forms!Forecast!TxtBudGWP,0))/Nz(Forms!Forecast!TxtBudGWP,0)
1
2170
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 same sheet) and external duplicates (duplicates which exist outside this sheet). I have gone through lot of logics..some of which are ... - Common and currently testing out.. - First insert the excel sheet data into DB..then query by...
3
25092
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 compare a to b. If they're different then it will print out 'duplicates found'. The problem is that even after trying different arrays, some with duplicates some without, that 'b' rearranges the numbers. Here's an example: a='1934, 2311,...
0
9797
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
9644
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10547
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
9331
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
6954
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
5626
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...
1
4427
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 we have to send another system
2
3977
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3081
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.