Untitled
unknown
plain_text
2 years ago
2.7 kB
14
Indexable
<?php
class mathang {
// Lấy tất cả mặt hàng
// Lấy các mặt hàng theo danh mục
// Lấy một mặt hàng theo id
// Tăng lượt xem cho một mặt hàng
private $id;
private $tendanhmuc;
private $hinhanh;
public function getID() {
return $this->id;
}
public function setID($value) {
$this->id = $value;
}
public function getTenDM() {
return $this->tendanhmuc;
}
public function setTenDM($value) {
$this->tendanhmuc = $value;
}
public function laymathang() { // lấy tất cả mặt hàng.
$dbcon = DATABASE::connect();
try{
$sql = "SELECT * FROM mathang";
$cmd = $dbcon->prepare($sql);
$cmd->execute();
$result = $cmd->fetchAll();
return $result;
}
catch(PDOException $e){
$error_message = $e->getMessage();
echo "<p>Lỗi truy vấn: $error_message</p>";
exit();
}
}
public function laymathang_danhmuc($danhmuc_id) { // lấy mặt hàng theo danh mục
$dbcon = DATABASE::connect();
try{
$sql = "SELECT * FROM mathang WHERE danhmuc_id=:madm";
$cmd = $dbcon->prepare($sql);
$cmd->bindValue(":madm", $danhmuc_id);
$cmd->execute();
$result = $cmd->fetchAll();
return $result;
}
catch(PDOException $e){
$error_message = $e->getMessage();
echo "<p>Lỗi truy vấn: $error_message</p>";
exit();
}
}
public function laymathang_id($id) { // lấy mặt hàng theo id.
$dbcon = DATABASE::connect();
try{
$sql = "SELECT * FROM danhmuc WHERE id=:id";
$cmd = $dbcon->prepare($sql);
$cmd->bindValue(":id", $id);
$cmd->execute();
$result = $cmd->fetch();
return $result;
}
catch(PDOException $e){
$error_message = $e->getMessage();
echo "<p>Lỗi truy vấn: $error_message</p>";
exit();
}
}
public function tangluotxem($id) {
$dbcon = DATABASE::connect();
try{
$sql = "UPDATE mathang SET luotxem=luoitxem + 1 WHERE id=:id";
$cmd = $dbcon->prepare($sql);
$cmd->bindValue(":id", $mathang);
$cmd->execute();
$result = $cmd->fetch();
return $result;
}
catch(PDOException $e){
$error_message = $e->getMessage();
echo "<p>Lỗi truy vấn: $error_message</p>";
exit();
}
}
}
?>Editor is loading...