Gossamer Forum
Home : Products : DBMan : Customization :

How do I make this query?

Quote Reply
How do I make this query?
Hi,

I have a database with the following fields:

ID, Date, Time, Country, Number, Name, Gender, Userid, homepage and emailaddress.

I want to have a list, which shows from every country there is in the database, the first record. For example, I have:

Netherlands, john, male, 4-4-99 00:04
Netherlands, peter, male, 4-4-99 00:11
Mozambique, lotte, female, 4-4-00 04:05

I want the first and the last one, because that are different country's and they were the first.

The Country-field is a select-field (with a list of all country's).

Thanks in advance,

------------------
Jan
Quote Reply
Re: How do I make this query? In reply to
Do you want just the names of the countries to be listed or the entire record of the first entry for each country?

If you just want to list the countries that are currently in the database, you can add this code

Code:
$fieldnum = 3; # the number of your Country field
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name.
Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @countries)) {
push (@countries, $fields[$fieldnum]);
}
}
close DB;

At this point, all the countries in your database will be in an array called @countries. To print them out, use something like

Code:
foreach $country (@countries) {
print "$country<BR>";
}

If you want to print the entire record for the earliest entry from each country, it would be a lot more complicated.


------------------
JPD





Quote Reply
Re: How do I make this query? In reply to
Well, thanks for your answer... I want to show the whole record (with names, numbers etc...). Is there a subroutine which:

- first sort all country's from A to Z
- then sort this table on date
- then sort it on time
- then take's every first record?



------------------
Jan
Quote Reply
Re: How do I make this query? In reply to
Not that I know of. That's the sort of thing you would be able to do in MSAccess, with a series of queries, but in a flatfile database like DBMan, it's really complex. (I've learned not to say anything is impossible, though! Smile )

------------------
JPD