我有两个标题,我想根据帐户类型显示它们;"a"表示管理员类型,"b"表示常规用户类型。我已经有了枚举集"a"、"b"。现在,对于连接到数据库后的php,我有:
<?php
while ($row = mysql_fetch_array($sql)){
$name = $row["name"];
$accounttype = $row["accounttype"];
if($accounttype == "a"){
$header = include_once "header_a.php";
}
if($accounttype == "b"){
$header = include_once "header_b.php";
}
}
?>
至于html,我有:
<html>
<body>
<?php echo $accounttype; ?>
</body>
</html>
编辑:好的,我用正确的方式工作:
<?php
$header ="";
while ($row = mysql_fetch_array($sql)){
$name = $row["name"];
$accounttype = $row["accounttype"];
if($accounttype == "a"){
include_once "header_a.php";
}else{
include_once "header_b.php";
}
}
?>
<html>
<body>
<?php echo $header; ?>
</body>
</html>
为什么不这样做:
<?php
while ($row = mysql_fetch_array($sql)){
$name = $row["name"];
$accounttype = $row["accounttype"];
}
include_once "header_".$accounttype.".php";
?>
<html>
<body>
<?php echo $accounttype; ?>
</body>
</html>