0
我有一個名爲index.php的頁面,裏面,我的PHP我有CRUD的功能,我的問題是,我怎麼能分開的PHP代碼爲HTML,並把它放在一類..請幫助我..如何使用pdo將php代碼分離爲html?
這裏的PHP和HTML代碼,我想單獨
<label class="Land_Type">
<span>Land Type</span>
<?php
include_once 'dbconfig.php';
$sql = "SELECT Land_Type_Name FROM land_type";
$stmt = $DB_con->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($stmt->rowCount() > 0)
{
?>
<select name="Land_Type">
<option selected="selected" value="">---</option>
<?php
foreach ($results as $row)
{
?>
<option value="<?php echo $row['Land_Type_Name']; ?>"><?php echo $row['Land_Type_Name']; ?></option>
<?php
}
?>
</select>
<?php
}
?>
</label>
,這裏是我的課
<?php
class crud
{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function login($uname,$upass)
{
try
{
$stmt = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname LIMIT 1");
$stmt->execute(array(':uname'=>$uname));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0)
{
if(password_verify($upass, $userRow['user_pass']))
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function is_loggedin()
{
if(isset($_SESSION['user_session']))
{
return true;
}
}
看看MVC模式 – Bv202