这是我的代码:
<?php
ini_set('max_execution_time', 150);
require('db.php');
$values = array();
$data = array();
$username = $_GET['username'];
$username = $mysqli->real_escape_string($username);
$password = $_GET['password'];
$password = $mysqli->real_escape_string($password);
$query = $mysqli->query("SELECT premium_duration, vip_duration
FROM
users_account
WHERE
user_name='".$username."'
AND user_pass='".md5($password)."'
");
while($row = $query->fetch_assoc())
{
if($row['premium_duration'] > 0)
{
$timeremain = $row['premium_duration'];
$type = 'Premium';
}elseif($row['vip_duration'] > 0)
{
$timeremain = $row['vip_duration'];
$type = 'VIP';
}else{
$timeremain = 0;
$type = 'None';
}
$values['TimeRemain'] = $timeremain;
$values['Type'] = $type;
$data[] = $values;
}
echo json_encode(array("Durations" => ($data)));
?>
但这只会导致:
{“持续时间”:[{“ TimeRemain”:“ 15847800”,“ Type”:“ Premium”}]}
我想要实现的是:
{“持续时间”?{“ TimeRemain”:74973600,“类型”:“ Premium” },{“ TimeRemain”:0,“ Type”:“ VIP”}]}
我该怎么做?