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.

Get a list of a mysql select

Help for those learning Tcl or writing their own scripts.
Post Reply
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Get a list of a mysql select

Post by Psyfire »

Hello,

if I type this in phpmyadmin console:

Code: Select all

SELECT ps_plr.plrid, ps_plr.uniqueid, ps_plr.rank, ps_plr.skill, ps_plr_profile.name
FROM ps_plr, ps_plr_profile
WHERE allowrank =1
AND ps_plr.uniqueid = ps_plr_profile.uniqueid
ORDER BY skill DESC
LIMIT 10 
I get this list:

Code: Select all

710  	STEAM_0:1:1889849  	1  	1963.16  	()()7
803 	STEAM_0:1:12916169 	2 	1945.60 	brasil_fr.
953 	STEAM_0:1:859266 	3 	1881.20 	SriQst iZ qL
50 	STEAM_0:1:11381583 	4 	1848.65 	Uncle
902 	STEAM_0:0:14033485 	5 	1842.98 	The Prophet
976 	STEAM_0:1:14352136 	6 	1834.15 	w0ll4k
800 	STEAM_0:0:3850505 	7 	1815.94 	EmBri0.Iceman <AdemA>
1001 	STEAM_0:1:72535 	8 	1815.44 	busheteeeeeeeeeeeee
944 	STEAM_0:1:12625835 	9 	1781.13 	yohan
736 	STEAM_0:1:10075317 	10 	1757.44 	JaNoVsKi
Thats my output of the select. Now I want to implement this list via a /top10 command in a tcl script.

The problem is, that I dont know how to get this list with this all variables. Can somebody help me?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You'll probably have to use the mysqltcl interface, or something similar. If you use mysqltcl, the documentation is available on their homepage.
NML_375
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

I use mysqltcl in my script but I dont know how to create a list that ouputs that data.
w
w00f
Halfop
Posts: 49
Joined: Wed Oct 04, 2006 6:50 pm

Post by w00f »

Code: Select all

## CONF ##
# trigger to search top10
set srch(top10) "!top10"

# SQL info
set sql(host) "IP"
set sql(user) "USER"
set sql(pass) "PASS-BLA"
set sql(db) "DATABASE-NAME"
set sql(port) "PORT"

## END CONF ##

package require mysqltcl
bind pub - $srch(top10) srh_top

proc srh_top {nick host hand chan arg} {
	global sql
	set sql(handle) [mysqlconnect -host $sql(host) -user $sql(user) -password $sql(pass) -db $sql(db) -port $sql(port)]
	set query [::mysql::query $sql(handle) "SELECT ps_plr.plrid, ps_plr.uniqueid, ps_plr.rank, ps_plr.skill, ps_plr_profile.name FROM ps_plr, ps_plr_profile WHERE allowrank =1 AND ps_plr.uniqueid = ps_plr_profile.uniqueid ORDER BY skill DESC LIMIT 10"]
	while {[set row [::mysql::fetch $query]] != ""} {
	set plrid [lindex $row 0]
	set id [lindex $row 1]
	set rank [lindex $row 2]
	set skill [lindex $row 3]
	set name [lindex $row 4]
	putquick "PRIVMSG $chan :\00314\002\[\017\002#$rank\00314\]\002\00314 ~ \002\00307Player\017: $name \00314~\017 \002\00307Skill\017: $skill \00314~\002\00307 iD\017: $id \00314~\002\00307 PLRiD\017: $plrid "
	}
::mysql::endquery $query
mysqlclose $sql(handle)
}


putlog "Top10.tcl loaded"
didn't tested , but think its ok
Last edited by w00f on Wed Apr 25, 2007 4:17 pm, edited 1 time in total.
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

Tcl error [srh_top]: invalid command name "::mysql::query"
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Then you're using an older version of mysqltcl. The main difference is older version uses command-names such as mysqlquery while the newer uses namespaces, ie ::mysql::query.

In any case, the docs on their webpage should be enough to atleast get you started...
A good place to start would be the mysqlsel command...
NML_375
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

Building Dependency Tree... Done
mysqltcl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.

And now? I got the last version...
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Simply... if you've got mysqltcl v3.0, the ::mysql::query command should be available (obviously assuming you've loaded the module properly...)
If you're using any other version, it would be mysqlquery.
Since you failed to mention which version of mysqltcl you're using, I can't tell which syntax would be proper for you...
NML_375
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

I am running definitly 3.02.

The module is loaded of course, otherwise my other mysql scripts wont work and they work 100%.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, that error you reported above, does indicate that your module is either broken, or you've failed to load it properly.
You could always check your other scripts, that you say are working, for hints on what you'd have to change to make it work..
NML_375
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

I got it now thanks for the script, works fine.

The problem was that the updater said I got the newest version, but that was not correct.

I deinstalled the current version and installed a new fresh 3.02 now. Strange with this update thing but it works now :-)
Post Reply