我有一个表pcategory 里面有三个字段 id pname note我的111.php <link href="images/skin.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="css/flexigrid.css" />
<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#flex1").flexigrid
(
{
url: 'include/action/post2.php',
dataType: 'json',
colModel : [
{display: '编号', name : 'id', width : 40, sortable : true, align: 'center'},
{display: '类别名称', name : 'pname', width : 140, sortable : true, align: 'center'},
{display: '备注', name : 'note', width : 180, sortable : true, align: 'left'},
],
buttons : [
{name: '添加', bclass: 'add', onpress : test},
{name: '删除', bclass: 'delete', onpress : test},
{separator: true},
{name: 'A', onpress: sortAlpha},
{name: 'B', onpress: sortAlpha},
{name: 'C', onpress: sortAlpha},
{name: 'D', onpress: sortAlpha},
{name: 'E', onpress: sortAlpha},
{name: 'F', onpress: sortAlpha},
{name: 'G', onpress: sortAlpha},
{name: 'H', onpress: sortAlpha},
{name: 'I', onpress: sortAlpha},
{name: 'J', onpress: sortAlpha},
{name: 'K', onpress: sortAlpha},
{name: 'L', onpress: sortAlpha},
{name: 'M', onpress: sortAlpha},
{name: 'N', onpress: sortAlpha},
{name: 'O', onpress: sortAlpha},
{name: 'P', onpress: sortAlpha},
{name: 'Q', onpress: sortAlpha},
{name: 'R', onpress: sortAlpha},
{name: 'S', onpress: sortAlpha},
{name: 'T', onpress: sortAlpha},
{name: 'U', onpress: sortAlpha},
{name: 'V', onpress: sortAlpha},
{name: 'W', onpress: sortAlpha},
{name: 'X', onpress: sortAlpha},
{name: 'Y', onpress: sortAlpha},
{name: 'Z', onpress: sortAlpha},
{name: '#', onpress: sortAlpha} ],
searchitems : [
{display: '类别名称', name : 'pname'},
{display: '备注', name : 'note', isdefault: true}
],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Countries',
useRp: true,
rp: 10,
showTableToggleBtn: true,
width: 900,
height: 255
}
);
});
function sortAlpha(com)
{
jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[name=qtype]').val()}]});
jQuery("#flex1").flexReload();
}function test(com,grid)
{
if (com=='Delete')
{
if($('.trSelected',grid).length>0){
if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
var items = $('.trSelected',grid);
var itemlist ='';
for(i=0;i<items.length;i++){
itemlist+= items[i].id.substr(3)+",";
}
$.ajax({
type: "POST",
dataType: "json",
url: "include/action/delete.php",
data: "items="+itemlist,
success: function(data){
alert("Query: "+data.query+" - Total affected rows: "+data.total);
$("#flex1").flexReload();
}
});
}
} else {
return false;
}
}
else if (com=='Add')
{
alert('Add New Item Action');
}
}
</script>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #EEF2FB;
}
-->
</style>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
<td valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
<tr>
<td height="31"><div class="titlebt">分类信息</div></td>
</tr>
</table></td>
<td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
</tr>
<tr>
<td valign="middle" background="images/mail_leftbg.gif"> </td>
<td valign="top" bgcolor="#F7F8F9"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" valign="top"> </td>
<td> </td>
<td valign="top"> </td>
</tr>
<tr>
</tr>
<table id="flex1" style="display:none"></table>
</table>
</body>我的post2.php <?
error_reporting(0);
function runSQL($rsql) {
$hostname = "localhost";
$username = "root";
$password = "123456";
$dbname = "jxc";
$connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
$db = mysql_select_db($dbname);
$result = mysql_query($rsql) or die ('jxc');
return $result;
mysql_close($connect);
}function countRec($fname,$tname,$where) {
$sql = "SELECT count($fname) FROM $tname $where";
$result = runSQL($sql);
while ($row = mysql_fetch_array($result)) {
return $row[0];
}
}
$page = $_POST['page'];
$rp = $_POST['rp'];
$sortname = $_POST['sortname'];
$sortorder = $_POST['sortorder'];if (!$sortname) $sortname = 'id';
if (!$sortorder) $sortorder = 'desc';
if($_POST['query']!=''){
$where = "WHERE `".$_POST['qtype']."` LIKE '%".$_POST['query']."%' ";
} else {
$where ='';
}
if($_POST['letter_pressed']!=''){
$where = "WHERE `".$_POST['qtype']."` LIKE '".$_POST['letter_pressed']."%' ";
}
if($_POST['letter_pressed']=='#'){
$where = "WHERE `".$_POST['qtype']."` REGEXP '[[:digit:]]' ";
}
$sort = "ORDER BY $sortname $sortorder";if (!$page) $page = 1;
if (!$rp) $rp = 10;$start = (($page-1) * $rp);$limit = "LIMIT $start, $rp";$sql = "SELECT id,pname,note FROM pcategory $where $sort $limit";
$result = runSQL($sql);$total = countRec('pname','pcategory',$where);header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "\n{";
$json .= "id:'".$row['id']."',";
$json .= "cell:['".$row['id']."','".$row['pname']."'";
$json .= ",'".addslashes($row['note'])."'";
$json .= "}";
$rc = true;
}
$json .= "]\n";
$json .= "}";
echo $json;
?> 然后在111.php 里面一直加载不出来数据,请给为大侠帮看看 谢谢!
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="css/flexigrid.css" />
<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#flex1").flexigrid
(
{
url: 'include/action/post2.php',
dataType: 'json',
colModel : [
{display: '编号', name : 'id', width : 40, sortable : true, align: 'center'},
{display: '类别名称', name : 'pname', width : 140, sortable : true, align: 'center'},
{display: '备注', name : 'note', width : 180, sortable : true, align: 'left'},
],
buttons : [
{name: '添加', bclass: 'add', onpress : test},
{name: '删除', bclass: 'delete', onpress : test},
{separator: true},
{name: 'A', onpress: sortAlpha},
{name: 'B', onpress: sortAlpha},
{name: 'C', onpress: sortAlpha},
{name: 'D', onpress: sortAlpha},
{name: 'E', onpress: sortAlpha},
{name: 'F', onpress: sortAlpha},
{name: 'G', onpress: sortAlpha},
{name: 'H', onpress: sortAlpha},
{name: 'I', onpress: sortAlpha},
{name: 'J', onpress: sortAlpha},
{name: 'K', onpress: sortAlpha},
{name: 'L', onpress: sortAlpha},
{name: 'M', onpress: sortAlpha},
{name: 'N', onpress: sortAlpha},
{name: 'O', onpress: sortAlpha},
{name: 'P', onpress: sortAlpha},
{name: 'Q', onpress: sortAlpha},
{name: 'R', onpress: sortAlpha},
{name: 'S', onpress: sortAlpha},
{name: 'T', onpress: sortAlpha},
{name: 'U', onpress: sortAlpha},
{name: 'V', onpress: sortAlpha},
{name: 'W', onpress: sortAlpha},
{name: 'X', onpress: sortAlpha},
{name: 'Y', onpress: sortAlpha},
{name: 'Z', onpress: sortAlpha},
{name: '#', onpress: sortAlpha} ],
searchitems : [
{display: '类别名称', name : 'pname'},
{display: '备注', name : 'note', isdefault: true}
],
sortname: "id",
sortorder: "asc",
usepager: true,
title: 'Countries',
useRp: true,
rp: 10,
showTableToggleBtn: true,
width: 900,
height: 255
}
);
});
function sortAlpha(com)
{
jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[name=qtype]').val()}]});
jQuery("#flex1").flexReload();
}function test(com,grid)
{
if (com=='Delete')
{
if($('.trSelected',grid).length>0){
if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
var items = $('.trSelected',grid);
var itemlist ='';
for(i=0;i<items.length;i++){
itemlist+= items[i].id.substr(3)+",";
}
$.ajax({
type: "POST",
dataType: "json",
url: "include/action/delete.php",
data: "items="+itemlist,
success: function(data){
alert("Query: "+data.query+" - Total affected rows: "+data.total);
$("#flex1").flexReload();
}
});
}
} else {
return false;
}
}
else if (com=='Add')
{
alert('Add New Item Action');
}
}
</script>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #EEF2FB;
}
-->
</style>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
<td valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
<tr>
<td height="31"><div class="titlebt">分类信息</div></td>
</tr>
</table></td>
<td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
</tr>
<tr>
<td valign="middle" background="images/mail_leftbg.gif"> </td>
<td valign="top" bgcolor="#F7F8F9"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" valign="top"> </td>
<td> </td>
<td valign="top"> </td>
</tr>
<tr>
</tr>
<table id="flex1" style="display:none"></table>
</table>
</body>我的post2.php <?
error_reporting(0);
function runSQL($rsql) {
$hostname = "localhost";
$username = "root";
$password = "123456";
$dbname = "jxc";
$connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
$db = mysql_select_db($dbname);
$result = mysql_query($rsql) or die ('jxc');
return $result;
mysql_close($connect);
}function countRec($fname,$tname,$where) {
$sql = "SELECT count($fname) FROM $tname $where";
$result = runSQL($sql);
while ($row = mysql_fetch_array($result)) {
return $row[0];
}
}
$page = $_POST['page'];
$rp = $_POST['rp'];
$sortname = $_POST['sortname'];
$sortorder = $_POST['sortorder'];if (!$sortname) $sortname = 'id';
if (!$sortorder) $sortorder = 'desc';
if($_POST['query']!=''){
$where = "WHERE `".$_POST['qtype']."` LIKE '%".$_POST['query']."%' ";
} else {
$where ='';
}
if($_POST['letter_pressed']!=''){
$where = "WHERE `".$_POST['qtype']."` LIKE '".$_POST['letter_pressed']."%' ";
}
if($_POST['letter_pressed']=='#'){
$where = "WHERE `".$_POST['qtype']."` REGEXP '[[:digit:]]' ";
}
$sort = "ORDER BY $sortname $sortorder";if (!$page) $page = 1;
if (!$rp) $rp = 10;$start = (($page-1) * $rp);$limit = "LIMIT $start, $rp";$sql = "SELECT id,pname,note FROM pcategory $where $sort $limit";
$result = runSQL($sql);$total = countRec('pname','pcategory',$where);header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "\n{";
$json .= "id:'".$row['id']."',";
$json .= "cell:['".$row['id']."','".$row['pname']."'";
$json .= ",'".addslashes($row['note'])."'";
$json .= "}";
$rc = true;
}
$json .= "]\n";
$json .= "}";
echo $json;
?> 然后在111.php 里面一直加载不出来数据,请给为大侠帮看看 谢谢!
error_reporting(0);
function runSQL($rsql) {
$hostname = "localhost";
$username = "root";
$password = "123456";
$dbname = "jxc";
$connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
$db = mysql_select_db($dbname);
$result = mysql_query($rsql) or die ('jxc');
return $result;
mysql_close($connect);
}function countRec($fname,$tname,$where) {
$sql = "SELECT count($fname) FROM $tname $where";
$result = runSQL($sql);
while ($row = mysql_fetch_array($result)) {
return $row[0];
}
}
$page = $_POST['page'];
$rp = $_POST['rp'];
$sortname = $_POST['sortname'];
$sortorder = $_POST['sortorder'];if (!$sortname) $sortname = 'id';
if (!$sortorder) $sortorder = 'desc';
if($_POST['query']!=''){
$where = "WHERE `".$_POST['qtype']."` LIKE '%".$_POST['query']."%' ";
} else {
$where ='';
}
if($_POST['letter_pressed']!=''){
$where = "WHERE `".$_POST['qtype']."` LIKE '".$_POST['letter_pressed']."%' ";
}
if($_POST['letter_pressed']=='#'){
$where = "WHERE `".$_POST['qtype']."` REGEXP '[[:digit:]]' ";
}
$sort = "ORDER BY $sortname $sortorder";if (!$page) $page = 1;
if (!$rp) $rp = 10;$start = (($page-1) * $rp);$limit = "LIMIT $start, $rp";$sql = "SELECT id,pname,note FROM pcategory $where $sort $limit";
$result = runSQL($sql);$total = countRec('pname','pcategory',$where);header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "{";
$json .= "\"id\":\"".$row['id']."\"";
$json .= ",\"pname\":\"".addslashes($row['pname'])."\"";
$json .= ",\"note\":\"".addslashes($row['mote'])."\"";
$json .= "}";
$rc = true;
}
$json .= "]\n";
$json .= "}";
echo $json;
?> flexigrid 有显示:Displaying 1 to 2 of 2 items但flexigrid 里面的数据都没有显示出来,不知道怎么回事?