By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Is there a better way to do this?

P: n/a

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

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:

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;
// 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
//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.


I ph*********** II No nation was ever ruined by I
I II trade, even seemingly the most I
I remove "3d6" to e-mail II disadvantageous. - Ben Franklin I

Jul 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.