我有一個switch語句,並且因爲任何原因它不改變變量。我將它默認定義爲一個,$ getpage只會回顯爲1,而不是1,10。我不知道我做錯了什麼。有人請幫忙。PHP開關語句無法正常工作
if (!isset($_SESSION['username'])) {
echo '<meta http-equiv="refresh" content="0; url=memberarea.php">';
}
else {
if (!isset($_GET['sex']) &&
!isset($_GET['age']) &&
!isset($_GET['page'])) {
$_GET['age'] = "x";
$_GET['sex'] = "x";
$_GET['page'] = 1;
$getage = mysqli_real_escape_string($connect, $_GET['age']);
$getsex = mysqli_real_escape_string($connect, $_GET['sex']);
$getpage = mysqli_real_escape_string($connect, $_GET['page']);
}
else {
if ($_GET['age'] != "12-15" ||
$_GET['age'] != "16-18" ||
$_GET['age'] != "19-25" ||
$_GET['age'] != "26-35" ||
$_GET['age'] != "36+") {
$_GET['age'] = "x";
$getage = mysqli_real_escape_string($connect, $_GET['age']);
}
else {
$getage = mysqli_real_escape_string($connect, $_GET['age']);
}
if ($_GET['sex'] != "male" ||
$_GET['sex'] != "female" ||
$_GET['sex'] != "x") {
$_GET['sex'] = "x";
$getsex = mysqli_real_escape_string($connect, $_GET['sex']);
}
else {
$getsex = mysqli_real_escape_string($connect, $_GET['sex']);
}
if (ctype_digit($_GET['page']) === FALSE || $_GET['page'] > 10) {
$_GET['page'] = 1;
$getpage = mysqli_real_escape_string($connect, $_GET['page']);
}
else {
$getpage = mysqli_real_escape_string($connect, $_GET['page']);
}
if ($getsex === "all") {
$getsex = "*";
}
if ($getage === "all") {
$getage = "*";
}
switch($getpage) {
case 1:
$getpage = "1,10";
break;
case 2:
$getpage = "11,20";
break;
case 3:
$getpage = "21,30";
break;
case 4:
$getpage = "31,40";
break;
case 5:
$getpage = "41,50";
break;
case 6:
$getpage = "51,60";
break;
case 7:
$getpage = "61,70";
break;
case 8:
$getpage = "71,80";
break;
case 9:
$getpage = "81,90";
break;
case 10:
$getpage = "91,100";
break;
}
}
使用不同的變量。它應該工作 – bksi
適合我... ... [演示](http://phpfiddle.org/lite/code/ejq-xd2) – Neal
默認不是強制性的 –