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 

Loop Help

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


Joined: 01 Dec 2008
Posts: 3

PostPosted: Mon Dec 01, 2008 8:37 am    Post subject: Loop Help Reply with quote

hey i made this code for my ircd network but it seems the loop wont work, it will show one user but if 2 users have the same ip it wont, any help would be greatful, code below Smile

Code:

       set sql "SELECT ip, username FROM `ircusers` WHERE ip = '$text'"
       set result [mysqlsel $db_handle $sql -list]
       if {$result > 0} {

for {set i 1} {$i < 10} {incr i 1} {

       set record [lindex $result $i];
       set ip [lindex $record 0];
       set username [lindex $record 1];


       set sql2 "SELECT joindate FROM `forumusers` WHERE username='$username'"
       set result2 [mysqlsel $db_handle $sql2 -list]

        set record2 [lindex $result2 $i];
        set joindate [lindex $record2 0];


also tried loop as
Code:

for {set i 0} {$i < 10} {incr i} {
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Dec 01, 2008 12:29 pm    Post subject: Reply with quote

Since you are using lists, have you considered using a foreach-loop? Saves you the hazzle of manually retrieving the row item for each iteration.

I am somewhat puzzled by why you use index $i rather than index 0 in your second query. Being separate tables, there is no way of guaranteeing the same ordering, especially without any sorting directive.
In fact, I would suggest you do a (sql)join instead, which would actually save you one query along with having all the info available at once.

That would be done something like below, edit to suite your needs. If needed, use some sql-client to verify the output of the query.
Code:
set sql "SELECT ip.ircusers, username.ircusers, joindate.forumusers FROM ircusers, forumusers WHERE username.ircusers = username.forumusers AND ip.ircusers = '[mysqlescape $text]'"
foreach [list ip username joindate] [mysqlsel $sql -flatlist] {
 #puthelp "PRIVMSG somewhere :IP: $ip, Username: $username, Join date: $joindate"
}

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
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