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.

mysql query help

Help for those learning Tcl or writing their own scripts.
Post Reply
F
Frozen1985
Voice
Posts: 1
Joined: Thu May 24, 2007 3:40 pm
Location: se

mysql query help

Post by Frozen1985 »

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
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!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Take a little look at these pieces from your code...

Code: Select all

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

Code: Select all

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

  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
Post Reply