我有以下代码使用从 A 到 B 的邮政编码的前 5 个字符检查“固定票价”。
所以如果LE675FE
是输入,$full_post_code_a = LE675F;
基本上我想做的是一个循环,它将使用前 4 个和 3 个字符检查数据库,所以$full_post_code_a = LE675F / LE675 and LE67
只是想知道怎么可能做到这一点?
private static function checkFixedFarePC($post_codes) {
self::$arr_postcodes = explode(",", $post_codes);
// Get full postcode of Pickup
$full_post_code_a = (self::$arr_postcodes[0]);
// Get full postcode of Destination
$full_post_code_b = (self::$arr_postcodes[1]);
// Get first 5 characters of pickup & destination postcode
$post_code_a = substr($full_post_code_a,0 ,5);
$post_code_b = substr($full_post_code_b,0 ,5);
// Pass postcodes to check if a fixed fare is possible
return self::getFixedFare($post_code_a, $post_code_b);
}
哪个被发送到以下功能:
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;
return $result;
}
catch (PDOException $pe) {
die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
}
任何帮助将非常感激!