I have the following function:
private static function getFixedFare($FixedFareId) {
$pdo = new SQL();
$dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);
try {
$query = "SELECT Fare FROM tblfixedfare
WHERE FixedFareId = :fixed_fare_id
AND DayHalf = :day_half";
$stmt = $dbh->prepare($query);
$stmt->bindParam(':fixed_fare_id', $FixedFareId, PDO::PARAM_INT);
$stmt->bindParam(':day_half', self::$day_half, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_COLUMN);
$stmt->closeCursor();
$dbh = null;
return $result;
}
catch (PDOException $pe) {
die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
}
}
Basically I want to change the query to do nine different selects, as follows:
$query = "SELECT Fare FROM tblfixedfare
WHERE FixedFareId = :fixed_fare_id
AND DayHalf = :day_half
AND CarType = 'Car'";
and
$query = "SELECT Fare FROM tblfixedfare
WHERE FixedFareId = :fixed_fare_id
AND DayHalf = :day_half
AND CarType = 'Est'";
and the same for all the other car types, 'Exec', 'ExecEst', '6B', '7B', '7W', '8B' and 'Bus' which will only ever be these car types.
I was hoping I could store each of these query results into different variables without having to do 9 different queries (reducing code). Such as a loop and then storing the results to $resultcar, $resultest and so on...
Not to sure how I would do this so any help would be much appreciated! :-)