簡體   English   中英

在一頁中執行此PHP + MYSQL的更好方法是什么?

[英]What is better approach of doing this PHP + MYSQL in one page?

我的方法:

<?

switch($id) 
{ 
    case 1:
?>
        a lots of html stuff goes here...
<?    
    break;  
    case 2:
?>
        a lots of html stuff goes here2...
<?    
    break;        
}

?>

有什么辦法可以做得更漂亮嗎? 我的意思是更具可讀性? 我真的很感激。 (還沒學會聰明...)

將HTML分成單獨的文件,並將它們包含在相關的塊中。

如前所述。 或者,如果您真的想將其分離出來,則可以使用Smarty等模板引擎

if語句在這里可能更干凈:

<? 
if ($id == 1) {  
?> 
        a lots of html stuff goes here... 
<?     
}
if ($id == 2) {
?> 
        a lots of html stuff goes here2... 
<?     
} 
?> 

我建議使用像Smarty這樣的完整模板解決方案(Cfreak已經提到過),將演示文稿與邏輯分開是一個好主意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM