我有以下两个php文件,我试图将所选选项中的值传递给基本php文件,并根据传递的文件显示信息。
fkm_test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8″ />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>APP FKMS</title>
<link rel="stylesheet" type="text/css" media="screen" href="../js/jquery-ui-1.10.3.custom_blackGreen/jquery-ui-1.10.3.custom/css/trontastic/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../js/jquery.jqGrid-4.5.2/css/ui.jqgrid.css" />
<script src="../js/jquery-ui-1.10.0.custom/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="../js/jquery.jqGrid-4.5.2/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../js/jquery.jqGrid-4.5.2/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
function fkm(Application) {
var app = document.getElementById("myApp").selectedIndex;
var app_selected = document.getElementsByTagName("option")[app].value;
alert (app_selected);
//alert(document.getElementsByTagName("option")[app].value);
var lastSel
$("#list").jqGrid({
url: "fkm_display.php?app=$app_selected",
editurl: "fkmedit.php",
datatype: "json",
mtype: "GET",
colNames: ["App", "Pattern Type", "Pattern", "Rank", "AMRS", "EMEA", "APAC", "Audit", "ID", "Alert Type", "Comments"],
colModel: [
{ name: "division", width: 75 , editable: true},
{ name: "pattern_type", width: 90, editable: true, edittype:"select",formatter:'select', editoptions:{value:"BASIC:BASIC;REGEXP:REGEXP;REGEXP_IGNORE_CASE:REGEXP_IGNORE_CASE" } },
{ name: "pattern", width: 650, editable: true },
{ name: "rank", width: 50 },
{ name: "amrs_active", width: 40, editable: true, edittype:"select",formatter:'select', editoptions:{value:"1:Active;0: " } },
{ name: "emea_active", width: 40, editable: true, edittype:"select",formatter:'select', editoptions:{value:"1:Active;0: " } },
{ name: "apac_active", width: 40, editable: true, edittype:"select",formatter:'select', editoptions:{value:"1:Active;0: " } },
{ name: "audit", width: 200},
{ name: "id", width: 10, hidden: true},
{ name: "type", width: 20, editable: true, edittype:"select", sorttype:"text",formatter:'select', editoptions:{value:"IGNORE:IGNORE;ALERT:ALERT;WARN:WARN" } },
{ name: "comments", width: 10, editable: true,hidden: true}
],
height: 'auto',
pager: "#pager",
rowNum: 90,
rowList: [10, 20, 30, 60, 90],
sortname: "rank",
sortorder: "asc",
viewrecords: false,
gridview: true,
autoencode: true,
toppager: true,
grouping:true,
groupingView : {
groupField : ['type'],
groupColumnShow : [true],
groupText : ['<b>{0} - {1} Item(s)</b>']
},
caption: "Application FKMs"
});
jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: 'cn', ignoreCase: true});
jQuery("#list").jqGrid('navGrid','#pager',{"add":true,"del":true, "edit":true,"search":false,"refresh":true,"view":false, "cloneToTop":true});
};
</script>
</head>
<body>
<form id="phpform" name="phpform" method="POST" action="javascript:fkm();">
<select name="Application" id="myApp" >
<option selected="selected">–Select Application–</option>
<?php
include ('app_dbconfig.php');
$sql = "SELECT * FROM applications order by Application asc";
$result = mysql_query($sql) or die("SQL Error 1: " . mysql_error());
while($row=mysql_fetch_assoc($result))
{
echo '<option value="' . $row['Application'] . '">' . $row['Application'] . '</option>';
}
?>
</select>
<input type="submit" name="testing" value="Submit" >
</form>
<div align="center">
<table id="list"><tr><td></td></tr></table></div>
<div id="pager"></div>
</body>
</html>
fkm_display.php
<?php
include("fkm_dbconfig.php");
$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
$app = $_GET['app_selected'];
if(!$sidx) $sidx =1;
$result = mysql_query("SELECT COUNT(*) AS count FROM global_itrs_fkms");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
$total_pages=0;
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
$filterResultsJSON = json_decode($_REQUEST['filters']);
if($filterResultsJSON){
$filterArray = get_object_vars($filterResultsJSON);
$filterResultsJSON = json_decode($_REQUEST['filters']);
$filterArray = get_object_vars($filterResultsJSON);}
$SQL = "select division,pattern_type,pattern,rank,amrs_active,emea_active,apac_active,concat(audit,' ', timestamp) as audit,id,type from global_itrs_fkms";
$counter = 0;
while($counter < count($filterArray['rules']))
{
$filterRules = get_object_vars($filterArray['rules'][$counter]);
if($counter == 0){
$SQL .= ' WHERE ' . division = '$app' . $filterRules['field'] . ' LIKE "%' . $filterRules['data'] . '%"';
}
else {
$SQL .= ' AND ' . $filterRules['field'] . ' LIKE "%' . $filterRules['data'] . '%"';
}
$counter++;
}
$SQL .= " order by $sidx $sord LIMIT $start, $limit";
echo $SQL;
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());
$responce['total'] = $total_pages;
$responce['page'] = $page;
$responce['records'] = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$responce['rows'][$i]['id']=$row[id];
$responce['rows'][$i]['cell']=array($row[division],$row[pattern_type],$row[pattern],$row[rank],$row[amrs_active],$row[emea_active],$row[apac_active],$row[audit],$row[id],$row[type]);
$i++;
}
echo json_encode($responce);
如果我将网址:“fkm_display.php?app = $ app_selected”改为 url:“fkm_display.php”,当我点击提交时,我会收到enitre db信息,我不知道不想要。我只需要与所选应用程序相关的信息。
答案 0 :(得分:0)
我不确定,你的实际问题是什么。可能是您的jQgrid网址格式不正确。你需要这样改变,
url: "fkm_display.php?app="+app_selected,
由于你的app_selected
是一个javascript变量而不是php变量。在您的服务器端,您需要获得这样的值,
$app = $_GET['app'];
但是你在php代码中使用的是$app = $_GET['app_selected'];
。因为您在jQgrid代码中将app_selected
的值设置为app
变量。希望这会有所帮助。