1

我没有那么大的编程技能,我正在努力处理这可能没什么大不了的部分。我需要从选定的客户帐户生成一个包含特定信息的表,从 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()
4

0 回答 0