PHP?action=list",postData:{'title':title,'sn':sn},//发送数据
page:1
}).trigger("reloadGrid"); //重新载入
});
});
$where = '';
$title = uniDecode($_GET['title'],'utf-8'); //获取查询关键字:名称
if(!empty($title))
$where .= " and title like '%".$title."%'";
$sn = uniDecode($_GET['sn'],'utf-8'); //获取查询关键字:编号
if(!empty($sn))
$where .= " and sn='$sn'";
//执行SQL
$result = mysql_query("SELECT COUNT(
) AS count FROM products where deleted=0".$where);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count']; //获取总记录数
//根据记录数分页
if ($count > 0) {
$total_pages = ceil($count / $limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages)
$page = $total_pages;
$start = $limit $page - $limit;
if ($start < 0 ) $start = 0;
//执行分页SQL
$SQL = "SELECT * FROM products WHERE deleted=0".$where." ORDER BY $sidx $sord
LIMIT $start,$limit";
$result = mysql_query($SQL) or die("Couldn t execute query." . mysql_error());
$responce->page = $page; //当前页
$responce->total = $total_pages; //总页数
$responce->records = $count; //总记录数
$i = 0;
//循环读取数据
while ($row =
MysqL_fetch_array($result,
MysqL_ASSOC)) {
$responce->rows[$i]['id'] = $row[id];
$opt = "
修改";
$responce->rows[$i]['cell'] = array (
$row['sn'],$row['title'],$row['size'],$row['os'],$row['charge'],$row['price'],$opt
);
$i++;
}
echo json_encode($responce); //
输出JSON数据
break;
case '' :
echo 'Bad request.';
break;
}
查询的
中文字符串
function uniDecode($str,$charcode) {
$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",toUtf8,$str);
return mb_convert_encoding($text,$charcode,'utf-8');
}
function toUtf8($ar) {
foreach ($ar as $val) {
$val = intval(substr($val,2),16);
if ($val < 0x7F) { // 0000-007F
$c .= chr($val);
}
elseif ($val < 0x800) { // 0080-0800
$c .= chr(0xC0 | ($val / 64));
$c .= chr(0x80 | ($val % 64));
} else { // 0800-FFFF
$c .= chr(0xE0 | (($val / 64) / 64));
$c .= chr(0x80 | (($val / 64) % 64));
$c .= chr(0x80 | ($val % 64));
}
}
return $c;
}