egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to search a list of results from an sql query?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Reserve
Voice


Joined: 18 Apr 2005
Posts: 6
Location: Nottingham, UK

PostPosted: Wed Jan 18, 2006 5:15 am    Post subject: How to search a list of results from an sql query? Reply with quote

I’m trying to write a script that queries a database, sorts the results and then searches the results for a match.

The select query will be something like

Code:
 mysqlsel $mysql "SELECT * FROM sql_table where last_event < $time"
 set mycount [mysqlresult $mysql rows?]
  mysqlmap $mysql {id name score kills} {
 }


I have googled and searched the forum and found a few matches but I can’t get what I'm trying to do to work and don’t seem to be getting any error messages to help work out why it’s not working.

Once I have the results from the query I need to build a list of id, name, score and kills and sort first on score (DESC) and then on kills (DESC). That bit of the problem I can do with the actual select statement. The bit I'm having problems with is I need to somehow generate an index number for each result starting from 1 and ending with the last result to the query as follows

Code:
  Index    name     score   kills
  1        name1    100     20
  2        name4    95      15
  3        name2    82      10
  4        name5    82      8
  5        name3    60      5

From this list I then need to do a search for a particular name and select that whole row but the important part of the row will be the index number for that row. I’ve seen references to lsearch and think this may be the way to do it but in not sure how to actually implement it.

Can anyone offer me any help or guidance with this script?

TIA

Regards

Reserve
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Thu Jan 19, 2006 1:25 am    Post subject: Reply with quote

build your result set as list of lists:
Code:

...
mysqlmap $db {id name score kills} {
...
lappend ::result [list $id $name $score $kills]
...
}

then you'll be able to sort by index in sublist:
Code:

proc foo {...} {
...
# sort by name
set ::result [lsort -index 1 $::result]
...
}

refer to lsort manpage for more info and examples
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber