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.
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
}
}
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
}
}
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.