Tra Từ Điển

Thời gianTiếtThứ 2Thứ 3Thứ 4Thứ 5Thứ 6
8g40 - 9g101Tiếng Việt
Tiếng Anh
Tiếng Việt
Tiếng Việt
9g10 - 9g302Nghỉ giải lao
Tiếng Anh
Nghỉ giải lao
Nghỉ giải lao
9g30 - 10g3Toán
Toán
Toán

Thursday, February 17, 2022

PHP#26MySQL#22 - Hướng đối tượng Phần 3+4

//lib.php

<?php
class tintuc{
private $link; //chứa mã kết nối
//kết nối:
function connect($host, $user, $pass, $db)
{
$this->link=@mysqli_connect($host,$user,$pass) or die("Không thể kết nối đến Server!");
mysqli_select_db($this->link,$db) or die("Không tồn tại DB này!");
mysqli_query($this->link,"set names 'utf8'");
}
//Xây dựng hàm query:
function query($sl)
{
$kq=mysqli_query($this->link,$sl) or die(mysqli_error());
return $kq;
}
//Xây dựng hàm fetch:
function fetch($kq)
{
$d=mysqli_fetch_array($kq);
return $d;
}
//Hàm num_rows:
function num_rows($kq)
{
return mysqli_num_rows($kq);
}
//Hàm thể loại:Lấy các thể loại theo ngôn ngữ và trạng thái:
function theloai($lang="vi", $anhien=1)
{
$sltl="select * from theloai where (lang='$lang' or '$lang'='') and (AnHien=$anhien or $anhien=-1) order by ThuTu ASC";
$kqtl=$this->query($sltl);
return $kqtl;
}
//Loại tin theo the loại:
function lt_tl($idtl)
{
$sllt="select * from loaitin where AnHien=1 and idTL=$idtl order by ThuTu ASC";
$kqlt=$this->query($sllt);
return $kqlt;
}
//Hàm lấy các tin nổi bật:
function tinnoibat($lang="vi", $sotin=4)
{
$sl="select * from tin where lang='$lang' and TinNoiBat=1 and AnHien=1 order by idTin DESC limit 0,$sotin";
$kq=$this->query($sl);
return $kq;
}
//Hàm lấy các tin xem nhiều:
function tinxemnhieu($lang="vi",$sotin=10)
{
$sl="select idTin,TieuDe from tin where lang='$lang' and AnHien=1 order by SoLanXem DESC limit 0,$sotin";
$kq=$this->query($sl);
return $kq;
}
//Lấy các tin mới nhất theo thể loại:
function tin_tl($idtl,$sotin=6)
{
$sltin="select * from tin where idLT in (select idLT from loaitin where idTL=$idtl and AnHien=1) and AnHien=1 order by idTin DESC limit 0,$sotin";
$kq=$this->query($sltin);
return $kq;
}
//Viết code cập nhật số lần xem của tin:
function solanxem($idtin)
{
$sl="UPDATE tin set SoLanXem=SoLanXem+1 where idTin=$idtin";
$kq=$this->query($sl);
return $kq;
}
//Chi tiết tin:
function chitiettin($idtin)
{
$sl="select idLT, TieuDe, TomTat, Content from tin where idTin=$idtin";
$kq=$this->query($sl);
return $kq;
}
//các tin cũ hơn(lấy 5 tin cũ hơn và cùng loại tin với tin đang mở, sắp xếp từ mới đến cũ
function tincuhon($idlt,$idtin,$sotin)
{
$sl="select * from tin where AnHien=1 and idLT=$idlt and idTin < $idtin order by idTin DESC limit 0,$sotin";
$kq=$this->query($sl);
return $kq;
}
//>Bạn đọc ý kiến:
function bandocykien($idtin)
{
$sl="select * from bandocykien where idTin=$idtin order by Ngay DESC";
$kq=$this->query($sl);
return $kq;
}

//Loạitin theo idLT:
function lt_id($idlt)
{
$sl="select Ten from loaitin where idLT=$idlt and AnHien=1";
$kq=$this->query($sl);
$d=$this->fetch($kq);
return $d['Ten'];
}
//Tin theo Loại:
function tin_loai($idlt)
{
$sl="select idTin from tin where idLT=$idlt and AnHien=1";
$kq=$this->query($sl);
return $kq;
}
//Tin theo Loại , sắp xếp, vị trí:
function tin_loai_vt($idlt,$vt,$sotin)
{
$sl="select * from tin where idLT=$idlt and AnHien=1 order by idTin DESC limit $vt,$sotin";
$kq=$this->query($sl);
return $kq;
}
}
?>

0 comments:

Post a Comment