| View previous topic :: View next topic |
| Author |
Message |
Rolet Voice
Joined: 01 Dec 2008 Posts: 3
|
Posted: Mon Dec 01, 2008 8:37 am Post subject: Loop Help |
|
|
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
| 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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Dec 01, 2008 12:29 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|
|