我有以下 PHP 代码:
//switch
if (isset($_GET['pg']))
$pg = $_GET['pg'];
else{
$pg = 'home';
}
switch ($pg){
case 'home':
if (file_exists("pages/home.php")){
include("pages/home.php");}
break;
case 'about':
if (file_exists("pages/about.php")){
include("pages/about.php");}
else{include_once("error.php");}
break;
case 'products':
if (file_exists("pages/products.php")){
include("pages/products.php");}
else{include_once("error.php");}
break;
case 'contact':
if (file_exists("pages/contact.php")){
include("pages/contact.php");}
else{include_once("error.php");}
break;
default:
if (file_exists("error.php")){
include("error.php");}
}
?>
如何通过 MySQL 查询进行此切换?我尝试过这样的事情,但不幸的是不起作用:
$SQLquery = "SELECT * FROM pages";
$result = mysql_query($SQLquery);
switch ($pg){
while($row = mysql_fetch_array($result)) {
case $row['id']:
include($row['id'].'.php');
break;
}
}