|
Bajed Novice
Joined: 15 Aug 2004 Posts: 33
|
Posted: Sun Jun 24, 2007 2:11 pm
How do I access database records by number? |
I have a database record listing varios things that I want to perform operations on one at a time. Example:
item1 = 5
item4 = 8
item32 = 2
And so on. I don't know the key names of each item though so I want to access them by number instead. is this possible? For example, on the first loop I want to do something to @myRec.1, which is item1/5... after I do this, i want to reduce the number 5 down to 4, and move to the next loop, when the number reaches 0 I'll remove that record from the database and continue, meaning we'd be on item4/8, then item4/7, and so on.
Does this make sense? Heh.
Any help would be appreciated. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Jun 24, 2007 5:52 pm |
Using #loopdb you can loop through a db variable. This will expose both the key and the value in the %key and %val predefined variables so that the script contained in this loop structure can act on them.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Sun Jun 24, 2007 11:15 pm |
Code: |
#loopdb @DBRecord {#noop do something here using %val or whatever;#var DBRecord.%{key} %eval(%number(%val) - 1);#if (%val = 1) {#delk DBRecord %key} {};#abort } |
The #abort stops the loop so that you're only ever working on the first key-value pair |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
|
|