| View previous topic :: View next topic |
| Author |
Message |
Danko Voice
Joined: 09 Mar 2006 Posts: 18
|
Posted: Mon May 15, 2006 9:46 am Post subject: Output to chan from MySQL db |
|
|
Hello, I'm using a small code for reading from a Mysql db and posting info to chan..
Here's my code:
| Code: |
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..?  |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Mon May 15, 2006 12:12 pm Post subject: |
|
|
There are several methods.
| Code: | | putquick "PRIVMSG $channel :Info ($id) $name is from $city[expr {[llength $newcity] ? " but has moved to $newcity" : ""}]" |
or something like,
| Code: | set line "Info ($id) $name is from $city"
if {[llength $newcity]} {
lappend line "but has moved to $newcity"
}
putquick "PRIVMSG $channel :$line" |
|
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Mon May 15, 2006 12:42 pm Post subject: |
|
|
didnt you rather mean 'append line " but has moved to $newcity"'?  _________________ 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... |
|
| Back to top |
|
 |
Danko Voice
Joined: 09 Mar 2006 Posts: 18
|
Posted: Mon May 15, 2006 3:08 pm Post subject: |
|
|
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..? |
|
| Back to top |
|
 |
|