문제

i have the below two php files and i trying to pass the value from the selected option to the base php file and display the information based on the passed file.

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);

If i change the url: "fkm_display.php?app=$app_selected" to url: "fkm_display.php" and when i click on submit am getting the enitre db information, which i don't want. I need only the information related to the application selected.

도움이 되었습니까?

해결책

I am not sure, what is your actual problem. May be your jQgrid URL has not correctly formatted. You need to change like this,

url: "fkm_display.php?app="+app_selected,

Since your app_selected is a javascript variable not php variable. And in your server side you need to get the value like this,

$app = $_GET['app'];

But you are using like $app = $_GET['app_selected']; in your php code. Because you are setting the value of app_selected to app variable in your jQgrid code. Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top