我有一個意外的T_ELSE在這個函數的最後一個else。小PHP函數中意外的T_ELSE
function QueryPeople($stringQuery, $table, $max, $cmd) {
$con = mysqli_connect("localhost","user","password", "host");
if ($cmd == "Option1") {
$SearchSQL = "SELECT signature, firstname, birthdate FROM $table WHERE lower(signature) LIKE ?" . $max;
if ($fetchData = $con->prepare($SearchSQL)) {
$fetchData->bind_param("s", "%".$stringQuery."%");
$fetchData->execute();
$fetchData->bind_result($signature, $firstname, $birthdate);
$rows = array();
}
} else if ($cmd == "Option2") {
$searchSQL = "SELECT signature, firstname, birthdate FROM $table WHERE birthdate = ?" . $max;
if ($fetchData = $con->prepare($searchSQL)) {
$fetchData->bind_param(":birthdate", $stringQuery);
$fetchData->execute();
$fetchData->bind_result($signature, $firstname, $birthdate);
$rows = array();
}
}
while ($fetchData->fetch()) {
$row = array(
'signature' => $signature,
'firstname' => $firstname,
'birthdate' => $birthdate,
);
$rows[] = $row;
}
return $rows;
} else { // <-- This else doesn't have an if
print_r($con->error); // <-- This else doesn't have an if
} // <-- This else doesn't have an if
}
我真的不明白爲什麼會發生這種情況。這兩個if塊應該是自包含的,並且兩者都是封閉的,然後它應該去的時候,只有如果如果東西看起來腥?
我還有其他幾個函數,其中沒有一個需要if($ con){,所以我不認爲這是問題。 – 2009-10-28 15:04:41