| View previous topic :: View next topic |
| Author |
Message |
MUSUL Voice
Joined: 26 Apr 2010 Posts: 5
|
Posted: Wed Apr 28, 2010 1:21 pm Post subject: Count msyql output |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Apr 28, 2010 1:28 pm Post subject: |
|
|
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 |
|
 |
MUSUL Voice
Joined: 26 Apr 2010 Posts: 5
|
Posted: Wed Apr 28, 2010 1:54 pm Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Apr 28, 2010 2:15 pm Post subject: |
|
|
0 through n-1, where n is the first argument on the command line. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Fri Apr 30, 2010 12:44 pm Post subject: |
|
|
| 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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Apr 30, 2010 1:22 pm Post subject: |
|
|
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 |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Fri Apr 30, 2010 2:56 pm Post subject: |
|
|
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 |
|
 |
|