我有一个 PHP 页面将 MySQL 选择编码为 JSON。我想添加一个“状态值”作为我数组的第一个对象。
PHP 代码
{
//CREATE USER UNKNOWN ARRAY RESULT
$Statusresult = mysql_query("SELECT TEXT_KEY, TEXT_VALUE FROM T_TEXTS WHERE TEXT_KEY = 'USER_FAILED' ") or die(mysql_error());
$Statusrows = array();
while($s = mysql_fetch_assoc($Statusresult))
{
$Statusrows[] = $s;
}
print json_encode($Statusrows);
}
这个结果是:
{
"TEXT_KEY" = "USER_FAILED";
"TEXT_VALUE" = "UNKNOWN USER";
}
我想添加第一个对象手册,以使结果如下所示:
{
"STATUS" = "1";
"TEXT_KEY" = "USER_FAILED";
"TEXT_VALUE" = "UNKNOWN USER";
}
我怎样才能做到这一点 ?
我已经尝试过这种方法,但不知何故有一个错误......
{
//CREATE USER UNKNOWN ARRAY RESULT
$Statusresult = mysql_query("SELECT TEXT_KEY, TEXT_VALUE FROM T_TEXTS WHERE TEXT_KEY = 'USER_FAILED' ") or die(mysql_error());
$Statusrows = array();
$Statusrows = { "STATUS" => "1" };
while($s = mysql_fetch_assoc($Statusresult))
{
// $Statusrows[] = $s;
array_push($Statusrows, $s);
}
print json_encode($Statusrows);
}