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 

mysql query help

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


Joined: 24 May 2007
Posts: 1
Location: se

PostPosted: Thu May 24, 2007 3:46 pm    Post subject: mysql query help Reply with quote

ive been told to run an eggdrop for my friend. and i cant script it good. so thats why i ask here. problem is the last output to irc. i cant get the $nick and $channel to be outputted to the irc channel from the mysql db

Quote:
code:

bind pub "-|-" !from finduser

proc finduser {nick host handle channel arg} {



set dbhost "192.168.0.100"
set dbuser "xxx"
set dbpass "xxx"
set dbname "test"

set db_handle [mysqlconnect -host $dbhost -user $dbuser -password $dbpass]
mysqluse $db_handle $dbname

if {$arg == ""} {
return 0
} else {

set search [string map {" " "%"} [lindex $arg]]

set query [mysqlsel $db_handle "SELECT * FROM `HL2` WHERE `information` LIKE '$search' AND `nick` LIKE '%' AND `Channel` LIKE '%'" -list]
if {$query==""} { putquick "PRIVMSG $channel :$arg not found." ; return }

foreach result $query {
set nick [lindex $nick]
set Channel [lindex $Channel 2]

putquick "PRIVMSG $channel :SOURCE: $search from $nick - $Channel"
}
}
}




anyone who could assist me in this small script?
thanks for replys!
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu May 24, 2007 4:26 pm    Post subject: Reply with quote

Take a little look at these pieces from your code...
Code:
set search [string map {" " "%"} [lindex $arg]]

Code:
  foreach result $query {
   set nick [lindex $nick]
   set Channel [lindex $Channel 2]
   putquick "PRIVMSG $channel :SOURCE: $search from $nick - $Channel"
  }


First error, lindex expects two arguments:
1. a list.
2. a number indicating which list item to fetch.
On several locations you've only supplied the first...

Secondly, there is no variable named Channel within your script, so trying to read $Channel would also generate an error.

Third, you never make any use of the variable result within your foreach-loop, making it more or less pointless. I assume you intended to extract the nick and channel fields from the sql-query result? If so, you really should be using something like this:
Code:
  foreach result $query {
   set n [lindex $result 0]
   set c [lindex $result 1]
....


And fourth, it would seem arg is not a tcl-list, and is thus not suitable to be used with lindex. You might considder splitting it into a list first.
_________________
NML_375, idling at #eggdrop@IrcNET
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