how to select 2nd row of sql query result in lua
if i execute a query in mysql select dialprefix,rateinitial from cc_ratecard where (dialprefix='001' or dialprefix='00123') ORDER BY LENGTH(dialprefix) DESC; result row1 | 001 | 0.01000 | row22 | 00123 | 0.02000 | and this is lua code local rates = {} local count = ""; assert(dbh:query(query, function(qrow) for key, val in pairs(qrow) do rates[key] = val freeswitch.consoleLog("INFO"," rates :"..key.. "..="..val.." \n") end count = qrow.count; end)) questios is 1 how to select 2nd row from result ? 2 how to count total rows ? 3 how to print all 2 rows in console ? any suggestios wellcome
The function you pass to dbh:query is a callback. It is run for every row in the result set, in order. 1) Will be qrow on 2nd invocation 2) 'count = count + 1' on each invocation 3) Print on all invocations. You should be seeing that already, so perhaps the 2nd row isn't selected by your SQL query? On 6 December 2014 at 05:31, Shabbir abbasi <shabbirabbasi92@gmail.com> wrote:
if i execute a query in mysql select dialprefix,rateinitial from cc_ratecard where (dialprefix='001' or dialprefix='00123') ORDER BY LENGTH(dialprefix) DESC;
result row1 | 001 | 0.01000 | row22 | 00123 | 0.02000 |
and this is lua code
local rates = {} local count = "";
assert(dbh:query(query, function(qrow) for key, val in pairs(qrow) do rates[key] = val freeswitch.consoleLog("INFO"," rates :"..key.. "..="..val.." \n") end count = qrow.count; end))
questios is 1 how to select 2nd row from result ? 2 how to count total rows ? 3 how to print all 2 rows in console ?
any suggestios wellcome
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
participants (2)
-
Shabbir abbasi
-
Steven Ayre