Ordinal number within a table
"Kapoor, Nishikant" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.html-template |
|---|---|
| Message-ID | <B4448B75FF74124ABB5793D8BFBEEA3901C13CAC@exccpgo04.corp.xcelenergy.com> |
I am looking to populate my template loop by assigning it the entire resultset in one shot as follows:
my $str = "SELECT \@row:=\@row+1 as row, <fields> FROM <tables> WHERE ...";
my $sth = $conn->prepare($st);
$sth->execute();
my $dataArr = $sth->fetchall_arrayref( {} );
$template->param(dataLoop => $dataArr);
I am getting NULL for row. The solution suggested by following thread does it for command line, but I need to run it from inside my perl script.
http://lists.mysql.com/mysql/185626
a) SET @row=0;
b) SELECT (@row:=@row+1) AS row, ename, empno FROM emp ORDER BY empno;
And I don't know how to run both (a) and (b) together in one statement. Running just (b) is what is producing NULL for row.
Thanks for your help,
Nishi
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click