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.

Output to chan from MySQL db

Help for those learning Tcl or writing their own scripts.
Post Reply
D
Danko
Voice
Posts: 18
Joined: Thu Mar 09, 2006 1:07 pm

Output to chan from MySQL db

Post by Danko »

Hello, I'm using a small code for reading from a Mysql db and posting info to chan..
Here's my code:

Code: Select all

proc finduser {nick host hand channel arg} {
global mysql 

 set search [string map {" " "%"} [lindex $arg]]
 
 set query [mysqlsel $mysql(conn) "SELECT * FROM `users` WHERE `name` LIKE '$search' ORDER BY id DESC LIMIT 3" -list]
 if {$query==""} { putquick "PRIVMSG $channel :$arg not found." ; return } 

  foreach result $query { 
  set id [lindex $result 0] 
  set name [lindex $result 1] 
  set city [lindex $result 2] 
  set newcity [lindex $result 3] 

  putquick "PRIVMSG $channel :Info ($id) $name is from $city"
 } 
}
This output to chan "Info ($id) $name is from $city" is usually okey when $newcity is blank
in mysql db, but if there's some text in newcity field in db, I'd like to change output to "Info ($id) $name is from $city but has moved to $newcity".
So how do I do that..? :?
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

There are several methods.

Code: Select all

  putquick "PRIVMSG $channel :Info ($id) $name is from $city[expr {[llength $newcity] ? " but has moved to $newcity" : ""}]" 
or something like,

Code: Select all

  set line "Info ($id) $name is from $city"
  if {[llength $newcity]} {
    lappend line "but has moved to $newcity"
  }
  putquick "PRIVMSG $channel :$line" 
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

didnt you rather mean 'append line " but has moved to $newcity"'? :D
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
D
Danko
Voice
Posts: 18
Joined: Thu Mar 09, 2006 1:07 pm

Post by Danko »

Hoh, thanx - that worked like a charm. :)

However, a second question qbout MySQL..
My db is MyISAM as described above.. However, when I'm adding data to it (checking if $name allready exists before adding) it's slow and 'hanging' the computer for 1-2 seconds.. I'm no sql guru, but what might I be doing wrong..?
Post Reply