473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Is there a better way to do this?


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
\---+----+----+----+----+----+----++----+----+----+----+----+----+---/

Jul 16 '05 #1
0 1569

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: ForHimself Every Man | last post by:
What's better about Rattlesnakes than Python. I'm sure there's something. What is it? This is not a troll. I'm a snake shooping and I want people's answers. I don't know beans about...
10
by: michael newport | last post by:
Dear friends of database(s), After 13 years of Ingres, I am now using Oracle. But is Oracle technically better than Ingres. I would be much obliged if anyone could shed some light on the...
24
by: Faith Dorell | last post by:
I really donīt like C.You can write better programs in BASIC than in C, if you donīt like this language. I donīt understand how C became so popular, although much better programming languages...
39
by: bazad | last post by:
Hi, I am not using C all the time. I have a general understanding of C and nothing else. The recent reply to use strlcpy and strlcat showed me that I am not aware of the best and safe...
2
by: monkeydragon | last post by:
Which is better, using ReadFile/WriteFile or use fstream?
33
by: Protoman | last post by:
Which is better for general-purpose programming, C or C++? My friend says C++, but I'm not sure. Please enlighten me. Thanks!!!!!
22
by: JoeC | last post by:
I am working on another game project and it is comming along. It is an improvment over a previous version I wrote. I am trying to write better programs and often wonder how to get better at...
21
by: gavino | last post by:
why?
3
by: Ryan Liu | last post by:
Hi, Is Async I/O (e.g. NetworkStream.Begin/End Read/Write) always better than synchronous I/O? At least as good? When I don't concern about easy or difficult to write code, should I always...
43
by: Pawel_Iks | last post by:
I've read somewhere that c++ is something more than better c ... then I talk with my friend and he claimed that c++ is nothing more than better c ... I tried to explain him that he was wrong but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.