如何选择从现有字段计算的自定义值?
例如,我正在存储出生日期,并且我想选择从 mySql 函数计算的年龄。
$app->get("/users/:id", function ($id) use ($app, $db) {
$user = $db->users()->where("users_id", $id);
if ($data = $user->fetch()) {
$hobbies = array();
foreach ($data->users_hobbies() as $hobbie) { // get all tags of $application
$hobbies[] = $hobbie["users_hobbies_name"]; // print the tag name
}
echo json_encode(array(
"id" => $data["users_id"],
"login" => $data["users_login"],
"mail" => $data["users_mail"],
"date_of_birth" => $data["users_date_of_birth"],
"age" => ??
"hobbies" => $hobbies
));
} else {
echo json_encode(array(
"status" => false,
"message" => "User ID $id does not exist"
));
}
});