| View previous topic :: View next topic |
| Author |
Message |
festiz Voice
Joined: 03 Dec 2004 Posts: 3
|
Posted: Fri Dec 03, 2004 6:57 pm Post subject: errh?? |
|
|
My problem is that my script won't enter my foreach-loop if there is no user with nick=$nick. Wich means that my if-statement is useless. Is there some way to transform my foreach to a combined if-statement that does what my if-statement should do?
In PHP i would have checked if number of results from the query is larger than zero, but I can't find a manualpage for mysqltcl that mentions this kind of function.
| Code: |
foreach query [mysqlsel $mysql(conn) "SELECT nick FROM users WHERE nick='$nick' ORDER BY nick LIMIT 1" -list] {
set test "[lindex $query 0]"
if { $test eq "" } {
set mysql(conn) [mysqlconnect -user $mysql(user) -password $mysql(pass) -db $mysql(data)]
mysqlexec $mysql(conn) "INSERT INTO $mysql(table) ('nick' , 'uname') VALUES ('$nick','$uhost')"
# SOME NICE OUTPUT THAT SAYS: This is how u register.
} else {
# SOME NICE OUTPUT THAT SAYS: You are already registered
}
}
|
*Happy hugs*
Cut-n-paste-o-mania |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Fri Dec 03, 2004 10:38 pm Post subject: |
|
|
| Code: |
set resultset [mysqlsel $mysql(conn) "SELECT nick FROM users ...]
if {$resultset == {}} {
# not found in db, register/insert follows
#
} else {
# found in db, loop through result set
foreach result $resultset {
# use $result
}
}
|
|
|
| Back to top |
|
 |
T-Xorcist Halfop
Joined: 14 Nov 2005 Posts: 47 Location: Netherlands
|
Posted: Thu May 11, 2006 6:26 pm Post subject: |
|
|
I try this:
| Code: | package require mysqltcl
set mysql(conn) [mysqlconnect -user user -db tbot -password pass]
foreach name [mysqlsel $mysql(conn) "SELECT name FROM channels" -list] {
putquick "PRIVMSG $chan :$name "
}
mysqlclose $mysql(conn) |
There are 3 records in the database, but it only displays one, not all.
What am I doing wrong?
Please help, I am trying 3 days now to get it done, but I just can't
I tried this aswell:
| Code: | set query1 [mysqlquery $mysql(conn) {SELECT name FROM channels}]
while {[set row [mysqlnext $query1]]!=""} {
set name [lindex $row 0]
putquick "PRIVMSG $chan :$name"
}
mysqlendquery $query1 |
Doesn't work either! Is it my mysqltcl maybe? I run FreeBSD by the way.
It only displays the 1st record, not all 3
Please help me and let me know if the scripts are good. _________________ is-1337.org IRC server! |
|
| Back to top |
|
 |
|