请查看此prototype。
该页面上显示所有相关的客户端代码。以下是相关的服务器端代码:
use Locale::Currency::Format;
use strict;
use warnings;
my $db = 'profitorius';
my $hostname = 'localhost';
my $user = 'me';
my $dbpwd = 'mypw';
my $dbh = DBI->connect_cached("DBI:mysql:database=$db;host=$hostname",$user,$dbpwd,{RaiseError => 1}) or die "Failed to connect to the DB.\n";
my $cgi = CGI->new;
my $mid = $cgi->param('mid');
print $cgi->header(-type => 'text/xml;charset=latin1');
my $page = 1;
my $total_pages = 1;
my $s = "<?xml version='1.0' encoding='latin1'?><rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
unless (defined $mid) {
my $rcnt = 0;
$s .= "<records>".$rcnt."</records></rows>";
print $s;
exit;
}
my $sql = "SELECT id, Product_name, price, customization, custom_price FROM merchant_products WHERE mid = $mid;";
my $sth = $dbh->prepare($sql);
$sth->execute;
my $tbl_ary_ref = $sth->fetchall_arrayref;
my @ary = @$tbl_ary_ref;
my $rcnt = @ary;
$s .= "<records>".$rcnt."</records>";#<rows>
foreach my $v (@ary) {
my @r = @$v;
$r[2] = currency_format('USD',$r[2], FMT_HTML);
$s .= "<row id='". $r[0]."'>";
$s .= "<cell>". $r[0]."</cell>";
$s .= "<cell>". $r[1]."</cell>";
$s .= "<cell>". $r[2]."</cell>";
$s .= "<cell>". $r[3]."</cell>";
$s .= "<cell>". $r[4]."</cell>";
$s .= "</row>";
}
$s .= "</rows>";
print $s;
exit;
我知道最后一列需要格式化为货币,但这不是问题。
显然我一定错过了jqGrid文档中的内容,但问题是什么。
由于
泰德