| View previous topic :: View next topic |
| Author |
Message |
danwa Voice
Joined: 17 Oct 2011 Posts: 2
|
Posted: Mon Oct 17, 2011 11:56 pm Post subject: Returning Results |
|
|
Using this in conjunction with the mysql eggdrop module
http://www.barkerjr.net/eggdropmodules.html
http://wiki.barkerjr.net/wiki/MySQL_Module#Tcl_Commands
| Code: | proc mysql {n u h c a} {
mysql_connect dbname dbhost dbuser dbpass
mysql_query "select * from Residential WHERE Phone1 = 'a'"
puthelp "PRIVMSG $c: $a"
mysql_errno
}
bind pub -|- !mysqlquery mysql |
In the Table Residential there is a field named Phone1 that is populated in every row.
I can't get it to return anything, saying that, i'm not very confident with TCL. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Oct 18, 2011 2:25 am Post subject: |
|
|
The script isn't working cos you forgot to fetch the results after you've queried the database. Don't know your database structure so I will fetch first 3 rows of the database and you should change this.
| Code: |
set db(host) "localhost"
set db(user) "user"
set db(pass) "secret"
set db(dbase) "search"
bind pub -|- !mysqlquery mysql
proc mysql {nick uhost hand chan txt} {
global db
set db_handle [mysqlconnect -host $db(host) -user $db(user) -password $db(pass) -db $db(dbase)]
set results [mysqlquery $db_handle "SELECT * from Residential WHERE Phone1 = 'a'"]
if {![moreresult $results]} {
puthelp "PRIVMSG $chan :Couldn't find any matches."
} else {
puthelp "PRIVMSG $chan :Matches:"
while {[set row [mysqlfetch $results]] != ''} {
set row1 [lindex $row 0]
set row2 [lindex $row 1]
set row3 [lindex $row 2]
puthelp "PRIVMSG $chan :row1: $row1, row2: $row2, row3: $row3"
}
mysqlendquery $results
}
mysqlclose $db_handle
}
|
Haven't tested this but in theory should work, if you change the database info and the rows. Let me know if it doesn't.  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Oct 18, 2011 3:23 am Post subject: |
|
|
The code posted by caesar is written for the mysqltcl tcl module, not BarkerJr's eggdrop module. Personally, I'd recommend the mysqltcl module as well, as it's a bit more flexible, and remains the same across other tcl-based applications.
That said, the problem with your script, is that you don't use the return-value of the mysql_query command:
| Code: | ...
mysql_query "select * from Residential where Phone1 = 'a'"
.. |
To store the result in a variable, use this:
| Code: | | set result [mysql_query "select * from Residential where Phone1 = 'a'"] |
Now you can send the result to the channel, one record at a time:
| Code: | foreach item $result {
puthelp "PRIVMSG $c :Record: $item"
## Or perhaps a little neater:
# puthelp "PRIVMSG $c :Record: [join $item ", "]"
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
danwa Voice
Joined: 17 Oct 2011 Posts: 2
|
Posted: Tue Oct 18, 2011 7:46 am Post subject: |
|
|
Thanks for letting me know guys  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Oct 19, 2011 1:08 am Post subject: |
|
|
Thanks nml375. I forgot to mention that. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
|