This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

errh??

Help for those learning Tcl or writing their own scripts.
Post Reply
f
festiz
Voice
Posts: 3
Joined: Fri Dec 03, 2004 8:22 am

errh??

Post by festiz »

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: Select all

	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
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

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
  }
}
T
T-Xorcist
Halfop
Posts: 47
Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:

Post by T-Xorcist »

I try this:

Code: Select all

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? :cry:

Please help, I am trying 3 days now to get it done, but I just can't :cry:

I tried this aswell:

Code: Select all

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 :oops: and let me know if the scripts are good.
Post Reply