Ok I have a bit of a messy problem, and I can code this solution but I'm
hoping someone here can help me find a bit more elegant way to do this.
basically I have a table in in the DB (postgresql) that looks something like
this:
Table - logdata
codes time
===========================================
TXD 01:00
code three 01:00
RTX 01:10
code four 01:10
PXD 02:00
code six 02:00
TXD 01:45
code five code one 01:45
TXD 03:00
code five code six 03:00
TXD 04:00
code nine 04:00
....
....
As you can see from the times the idea is that there is a three letter
code type and a code level(s), these should be separate fields, and
delimited etc... but due to some dumb ass Perl programmer, I have to live
with this.
What I need to do is list just the code levels for TXD types, and only
list each code level once.
ie. the above should produce:
codes
=====
01
03
05
06
09
so basically I've come up with this:
// setup variables
$a = TRUE;
$codes = array( "code one" => "01", "code two" => "02", etc..........)
// limit it to just TXD entries
$ttime = pg_exec("select time from logdata where code='TXD' order by time");
while ( $a == TRUE )
{
$timerow = pg_fetch_row($ttime);
if ( is_null($timerow[0]))
{
$a = FALSE;
}
else
{
// get code sentences
$coderow = pg_fetch_row(pg_exec("select code from logdata where
time='$timerow[0]' order by code;"));
foreach ( $codes as $ctemp => $vtemp)
{
if ( substr_count($coderow,$ctemp) > 0 )
{
// build array of all codes
$code[]=$vtemp;
}
}
}
}
//trim code array to unique codes
$result = array_unique ($code);
//and a sort to make it nice
sort ($result);
this should leave me with what I need (I hope). Of course the table I'm
dealing with is actually far more complex, as are the sentences I'm
parsing, but this gets the major idea across. That whole while/foreach
loop strikes me as needlessly ugly though, and I haven't actually tested
this code so I have no idea if it would all work the way I think it does.
Which is where I'd like you guys to come in, and at least tell me I'm on
the right track, and hopefully suggest a few more elegant ways to pull
this off.
Thanx
--
/---+----+----+----+----+----+----++----+----+----+----+----+----+---\
I
ph***********@libertydice.org II No nation was ever ruined by I
I
http://www.libertydice.org II trade, even seemingly the most I
I remove "3d6" to e-mail II disadvantageous. - Ben Franklin I
\---+----+----+----+----+----+----++----+----+----+----+----+----+---/