egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Output to chan from MySQL db

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Danko
Voice


Joined: 09 Mar 2006
Posts: 18

PostPosted: Mon May 15, 2006 9:46 am    Post subject: Output to chan from MySQL db Reply with quote

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..? Confused
Back to top
View user's profile Send private message
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Mon May 15, 2006 12:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Mon May 15, 2006 12:42 pm    Post subject: Reply with quote

didnt you rather mean 'append line " but has moved to $newcity"'? Very Happy
_________________
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
View user's profile Send private message MSN Messenger
Danko
Voice


Joined: 09 Mar 2006
Posts: 18

PostPosted: Mon May 15, 2006 3:08 pm    Post subject: Reply with quote

Hoh, thanx - that worked like a charm. Smile

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber