我有1个database.In,我有1个tabel。我在这段代码中做json解析。
我使用这个php代码来检索值:
<head>
<style type="text/css">
.auto-style1 {
text-align: right;
}
</style>
</head>
<?php
echo getdata($_REQUEST['lastupdate']);
function getdata($lastupdatedate){
$obj = json_decode($json);
$con = mysql_connect("localhost","root","Password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("roster", $con);
$query = "select * from statedeathtax_v2 where LastUpdated > '".$lastupdatedate."' order by LastUpdated";
$rs = mysql_query($query) or die($query);
//print_r($rs);
while($row=mysql_fetch_assoc($rs)){
$record[] = $row;
}
$data = json_encode($record);
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
return $data;
}
?>在这里,这段代码没有显示"$“这样的特殊字符。当我在这段代码中抛出查询时,它显示了具有特殊字符的列的空值。我不明白这个问题。
发布于 2012-11-08 20:11:34
我已经解决了问题:
更新的代码:
<?php
echo getdata($_REQUEST['lastupdate']);
function getdata($lastupdatedate){
$obj = json_decode($json);
$con = mysql_connect("localhost","root","Password@123");
mysql_set_charset('utf8',$con);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("roster", $con);
$query = "select * from statedeathtax_v2 where LastUpdated > '".$lastupdatedate."' order by LastUpdated";
$rs = mysql_query($query) or die($query);
//print_r($rs);
while($row=mysql_fetch_assoc($rs)){
$record[] = $row;
}
$data = json_encode($record);
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: application/json; charset=utf-8' );
return $data;
}
?>https://stackoverflow.com/questions/13282835
复制相似问题