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.
Help for those learning Tcl or writing their own scripts.
MUSUL
Voice
Posts: 5 Joined: Mon Apr 26, 2010 4:02 pm
Post
by MUSUL » Wed Apr 28, 2010 1:21 pm
Hello,
How can count all the results from a sql query? Im trying this:
Code: Select all
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."
nml375
Revered One
Posts: 2860 Joined: Fri Aug 04, 2006 2:09 pm
Post
by nml375 » Wed Apr 28, 2010 1:28 pm
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
MUSUL
Voice
Posts: 5 Joined: Mon Apr 26, 2010 4:02 pm
Post
by MUSUL » Wed Apr 28, 2010 1:54 pm
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?
nml375
Revered One
Posts: 2860 Joined: Fri Aug 04, 2006 2:09 pm
Post
by nml375 » Wed Apr 28, 2010 2:15 pm
0 through n-1, where n is the first argument on the command line.
NML_375
raider2k
Op
Posts: 140 Joined: Tue Jan 01, 2008 10:42 am
Post
by raider2k » Fri Apr 30, 2010 12:44 pm
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
nml375
Revered One
Posts: 2860 Joined: Fri Aug 04, 2006 2:09 pm
Post
by nml375 » Fri Apr 30, 2010 1:22 pm
raider2k:
Please re-read the documentation for rand:
rand <limit>
Returns: a random integer between 0 and limit-1
Module: core
NML_375
raider2k
Op
Posts: 140 Joined: Tue Jan 01, 2008 10:42 am
Post
by raider2k » Fri Apr 30, 2010 2:56 pm
correct
the command applies to random between 0 and limit-1, so if limit is 100, the max value is 99, sorry.