| View previous topic :: View next topic |
| Author |
Message |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Fri Dec 29, 2017 6:16 am Post subject: Data Output |
|
|
Hi guys just scripted a small proc to display bots and owners from a database it outputs like this atm
| Code: | [9:48am] <~TurQ> !owners
[9:48am] <+ClonE> [OWNERS] *** owns *******
[9:48am] <+ClonE> [OWNERS] *** owns ****
[9:48am] <+ClonE> [OWNERS] *** owns ****
[9:48am] <+ClonE> [OWNERS] **** owns ****
[9:48am] <+ClonE> [OWNERS] *** owns ***
|
if possible i would to output it like this
| Code: | [OWNERS] owner1 owns bot1, bot2, bot3
[OWNERS] owner2 owns bot1, bot2 |
so it would be one owner per line instead of multiple lines
here is my proc so far
| Code: | ###################################
## !owners ###################
###################################
proc dupe:owners { nick uhost hand chan arg } {
global mysql_ otable_ chan_ db_handle bopen bdiv bclose
if {![mysqlsel $db_handle "SELECT `id` , `owner` , `botname` FROM `bots`"]} {putnow "PRIVMSG $chan_(addbot) :No results found\."; return 0}
mysqlmap $db_handle {id owner botname} {
putnow "PRIVMSG $chan :${bopen}\00303OWNERS\003${bclose} \00314$owner owns $botname\003"
}
} |
many thx in advance
Last edited by COBRa on Thu May 17, 2018 11:40 am; edited 1 time in total |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Jan 29, 2018 6:57 am Post subject: |
|
|
Sorry for the late answer. You can achieve this directly from the select with:
| Code: |
SELECT owner, group_concat(botname) AS bots FROM bots GROUP BY owner
|
and the result is:
| Code: |
owner / bots
alterego / PREvision,dapre
DarkSide / DarkSide
MaTr1X / MaTr1X
TurQ / AddFeeD,KaNE,PR3,|PR3|,TRiAD
|
Your code becomes:
| Code: |
proc dupe:owners {nick uhost hand chan text} {
global mysql_ otable_ chan_ db_handle bopen bdiv bclose
if {![mysqlsel $db_handle "SELECT owner, group_concat(botname) AS bots FROM bots GROUP BY owner"]} {
putnow "PRIVMSG $chan_(addbot) :No results found\."
return
}
mysqlmap $db_handle {owner bots} {
putnow "PRIVMSG $chan :${bopen}\00303OWNERS\003${bclose} \00314$owner owns [join [split $bots ","] ", "]\003"
}
}
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
|
|
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
|
|