这是我的一个查询的 SQL:
private static function getFixedFare($post_code_a, $post_code_b) {
$pdo = new SQL();
$dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);
try {
$query = "SELECT VehicleSystemId, Fare FROM tblfixedfares
WHERE ShortPostCodeA = '$post_code_a'
AND ShortPostCodeB = '$post_code_b'
AND DayHalf = :day_half
AND VehicleSystemId IN ('Car', '6B')";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':day_half', self::$day_half, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_GROUP);
$stmt->closeCursor();
$dbh = null;
var_dump($result['Car']);
}
catch (PDOException $pe) {
die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
}
}
当我这样做时,var_dump($result['Car']);
我得到以下响应:
array(1) {
[0]=>
array(1) {
["Fare"]=>
string(3) "100"
}
}
我将如何获得价值'100'......所以基本上 ['Car'] ['Fare'] 的 $result ?
编辑 ::
var_dump($cars);
显示:
array(2) {
["Car"]=>
array(1) {
[0]=>
array(1) {
["Fare"]=>
string(3) "100"
}
}
["6B"]=>
array(1) {
[0]=>
array(1) {
["Fare"]=>
string(3) "700"
}
}
我试过了; $result['Car']['Fare'] - 但这是返回 NULL;