我没有这么大的编程技巧,我正在努力解决这个问题,这可能不是什么大问题。我需要生成一个包含所选客户帐户中特定信息的表,从MS SQL DB中检索它,可以选择编辑每个行和单元格。
我正在使用jqgrid生成网格,并使用操作按钮添加内联编辑选项。如果我在服务器端对数据库的php调用中专门定义查询,那么一切都很有效,但问题是我需要使用与特定帐户相关的信息填充网格。当我在进入登录页面和验证页面之前进入此屏幕时,我已经拥有了带有客户编号的php变量,我需要将其传递给jqgrid,以便我只能检索与之相关的信息。那个帐户。
以下是工作原理,首先是显示客户帐户信息的页面:
#customerinfo.php
<?php
$acctnum = $_SESSION['custnum'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
<script type="text/javascript">
$(function(){
$("#regphones").jqGrid({
url:'custregphone.php',
datatype: 'json',
mtype: 'POST',
colNames:['Actions','Autodialer ID','Customer #','Access #','Destination #','Description'],
colModel :[
{name:'act', index:'act', width:70, sortable:false},
{name:'autodialer_id', index:'autodialer_id', width:80, align:'center', sortable:true, editable:true, hidden:true},
{name:'account', index:'account', width:90, align:'center', sortable:true, editable:true, hidden:true},
{name:'dnis', index:'dnis', width:90, align:'center', sortable:true, editable:true},
{name:'destination', index:'destination', width:120, align:'center', sortable:true, editable:true},
{name:'description', index:'description', width:120, align:'center', sortable:true, editable:true}
],
pager: '#regphonesp',
rowNum:5,
rowList:[5,10,15],
sortname: 'dnis',
sortorder: 'desc',
viewrecords: false,
gridview: true,
scrollOffset:0,
gridComplete: function(){
var ids = jQuery("#regphones").jqGrid('getDataIDs');
for(var i=0;i < ids.length;i++){
var cl = ids[i];
be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=\"jQuery('#regphones').editRow('"+cl+"');\" />";
se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=\"jQuery('#regphones').saveRow('"+cl+"');\" />";
ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=\"jQuery('#regphones').restoreRow('"+cl+"');\" />";
jQuery("#regphones").jqGrid('setRowData',ids[i],{act:be+se+ce});
}
},
editurl: "custregphone_edit.php",
caption: 'Registered Phones',
});
jQuery("#regphones").jqGrid('navGrid',"#regphonesp",{edit:false,add:false,del:false});
});
</head>
<body>
...
Registered Numbers: <?php echo $acctnum; ?>
<table id="regphones"></table>
<div id="regphonesp"></div>
...
</body>
然后是custregphone.php:
<?php
include("functions_engtst.php");
$page = $_POST['page'];
$limit = $_POST['rows'];
$sidx = $_POST['sidx'];
$sord = $_POST['sord'];
$acctnum = $_POST['acctnum'];
if(!$sidx) $sidx =1;
$dbh = get_db("live");
$sth = $dbh->prepare("SELECT COUNT(*) AS count FROM REGPHONE WHERE ACCOUNT='3058318318'");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
$count = $row['count'];
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
$sth = $dbh->prepare("SELECT autodialer_id,account,dnis,destination,description FROM REGPHONE WHERE ACCOUNT= '3058318318' ORDER BY $sidx $sord");
$sth->execute();
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row=$sth->fetch(PDO::FETCH_ASSOC)){
$responce->rows[$i]['autodialer_id']=$row[autodialer_id];
$responce->rows[$i]['cell']=array("",$row[autodialer_id],$row[account],$row[dnis],$row[destination],$row[description]);
$i++;
}
echo json_encode($responce);
?>
此代码有效,但问题是我无法动态获取帐户信息,我必须在查询中指定它。我的问题是如何将变量 $ acctnum 传递给custregphone.php中的两个查询以获得如下内容:
$sth = $dbh->prepare("SELECT COUNT(*) AS count FROM REGPHONE WHERE ACCOUNT= $acctnum");
$sth->execute();
$sth = $dbh->prepare("SELECT autodialer_id,account,dnis,destination,description FROM REGPHONE WHERE ACCOUNT= $acctnum ORDER BY $sidx $sord");
$sth->execute()