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 

Count msyql output

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


Joined: 26 Apr 2010
Posts: 5

PostPosted: Wed Apr 28, 2010 1:21 pm    Post subject: Count msyql output Reply with quote

Hello,

How can count all the results from a sql query? Im trying this:

Code:
set sql "SELECT id FROM news"
   set query [mysql::query $db_handle $sql]
   
   if {[set row [mysqlnext $query]] != ""} { incr n 1 }
   
   putquick "PRIVMSG #test:$n news registered."
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Apr 28, 2010 1:28 pm    Post subject: Reply with quote

Either use the COUNT() SQL-function in your query to return the number of matching records, or consider using the ::mysql::result command with the "rows" option
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
MUSUL
Voice


Joined: 26 Apr 2010
Posts: 5

PostPosted: Wed Apr 28, 2010 1:54 pm    Post subject: Reply with quote

ok ty, working with mysql::result. Now i have another doubt.

Using rand function like this:

set n [rand 5]

what's the range for the rand? 1-5? 1-4?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Apr 28, 2010 2:15 pm    Post subject: Reply with quote

0 through n-1, where n is the first argument on the command line.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Fri Apr 30, 2010 12:44 pm    Post subject: Reply with quote

Code:
SELECT COUNT(*) FROM `news`


is most probably the best idea since selecting all rows, putting them into list and then incr every entry is a waste of data and also takes longer

about rand: the syntax is [rand ?maximum?] which means a random number between 0 and ?maximum? is being chosen
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Apr 30, 2010 1:22 pm    Post subject: Reply with quote

raider2k:
Please re-read the documentation for rand:
Quote:
rand <limit>
Returns: a random integer between 0 and limit-1
Module: core

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Fri Apr 30, 2010 2:56 pm    Post subject: Reply with quote

correct

the command applies to random between 0 and limit-1, so if limit is 100, the max value is 99, sorry.
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