Tuesday, 8 March 2022

PHP#33MySQL#29 - Đếm lượt truy cập (KẾT THÚC KHÓA HỌC)

//hitcounter.php
<?php
session_start(); 
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php 
include("../connect.php");
//cập nhật số luowhtj truy cập:
$sl="update counter set cnt=cnt+1";
mysqli_query($link,$sl);
//Lấy dữ liệu số lượt truy cập để hiển thị ra web:
$sl2="select * from counter";
$kq=mysqli_query($link,$sl2);
$d=mysqli_fetch_array($kq);

//Định dạng:
$chuoi=str_pad($d['cnt'],6,"0",STR_PAD_LEFT);
$luottrycap="";
for($i=0;$i<strlen($chuoi);$i++)
{
$tam=substr($chuoi,$i,1);
$luottrycap.="<img src='images/$tam.png'/>";
}

/*-Khi user truy cập vào website:
+lần đầu tuy cập: Lưu thông tin của user lên csdl
+Sau lần đầu tiên: cập nhtaaj lastvisit
- Xóa các dòng dữ liệu quá 1 phút (Quy ước thời gian để khẳng định online hay offline: 1 phút)
- Thống kê số liệu người dùng online, thành viên online, khác online*/
$id=session_id();
$timeout=60; //1 phút
if(isset($_SESSION['iduser']))
$user=$_SESSION['iduser'];
else $user="";
//$lastvisited=time(); //unix_timestamp()
//Kiểm tra user có trên csdl chưa:
$sl1="select * from user_online where id='$id'";
$kq1=mysqli_query($link,$sl1);
if(mysqli_num_rows($kq1))
{
//Đã có trong csdl thì cập nhật lại tông tin:
$sl2="select * from user_online set lastvisit=unix_timestamp(), user='$user' where id='$id'";
mysqli_query($link,$sl2);
}
else{
//Chưa có trong csdl thêm mới:
$sl2="insert into user_online values('$id',unix_timestamp(),'$user')";
mysqli_query($link,$sl2);
}

//Xóa những dòng đã quá thời gian quy ước:
$sl3="delete from user_online where unix_timestamp()-lastvisit > $timeout";
mysqli_query($link,$sl3);

//Thống kê tổng số người online:
$sl4="select count(*) as tongso from user_online";
$kq4=mysqli_query($link,$sl4);
$d4=mysqli_fetch_array($kq4);
//Định dạng:
$chuoi=str_pad($d4['tongso'],3,"0",STR_PAD_LEFT);
$tongso="";
for($i=0;$i<strlen($chuoi);$i++)
{
$tam=substr($chuoi,$i,1);
$tongso.="<img src='images/$tam.png'/>";
}

//Thống kê số thành viên online:
$sl5="select count(*) as souser from user_online where user!=''";
$kq5=mysqli_query($link,$sl5);
$d5=mysqli_fetch_array($kq5);
?>
<div>Lượt truy cập: <?php echo $luottrycap;?></div>
<div>Tổng sô người online: <?php echo $tongso;?></div>
<div>Sô thành viên online: <?php echo $d5['souser'];?></div>
</body>
</html>

Saturday, 5 March 2022

PHP#32MySQL#28 - Ajax3 + EMAIL

//connect.php

<?php
$link=@mysqli_connect("localhost","root","") or die("Khong the ket noi den server");
mysqli_select_db($link,"webtintuc") or die ("Kiem tra lai ten database!");
mysqli_query($link,"set names 'utf8'");
?>

Thursday, 3 March 2022

PHP#31MySQL#27 - Ajax2

//checkuser.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-3.6.0.js"></script>
</head>

<body>
<script type="text/javascript"> 
$(document).ready(function(){
$("#username").blur(function(){
$.ajax({
                    type:"POST",
                    url:"xuly_checkuser.php",
                    data:"user="+$("#username").val(),
                    success:function(abc)
{
                        if(abc=="1")
$("#kq").html("User này đã tồn tại. Mời bạn chọn user khác!");
else
{
$("#kq").html("User này chưa có. Bạn có thể sử dụng");
$("#dangky").removeAttr("disabled");
}
                    }
})
})
//Viết code cho sự kiện focus lên username:
$("#username").focus(function(){
$("#dangky").attr("disabled",true);
$("#kq").html("");
})
    });
</script>

<form method="get" id="form1" name="form1" action="">
  <p>
    <label for="textfield">Họ Tên:</label>
    <input type="text" name="hoten" id="hoten">
  </p>
  <p>
    <label for="username">Username:</label>
    <input type="text" name="username" id="username"><br/>
    <div id="kq"></div>
  </p>
  <p>
    <label for="password">Password:</label>
    <input type="password" name="password" id="password">
  </p>
  <p>
    <label for="confirmpassword">Re Password:</label>
    <input type="password" name="confirmpassword" id="confirmpassword">
  </p>
  <p>
    <input type="submit" name="dangky" id="dangky" value="Đăng ký" disabled>
  </p>
</form>
</body>
</html>

PHP#30MySQL#26 - Ajax

Thursday, 24 February 2022

PHP#29MySQL#25 - Captcha & Bình chọn

//CAPTCHA: vidu.php

<?php
session_start();
//phát sinh 6 ký tự ngẫu nhiên:
$dodai=6;
$chuoi="QWERTYUIOPASDFGHJKLZXCVBNM0123456789";
$capt="";
for($i=1;$i<=$dodai;$i++)
{
$vitri=rand(0,35);
$capt.=substr($chuoi,$vitri,1);
}
$_SESSION['captcha']=$capt;
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="xuly.php" name="form1"id="form1" method="post">
  <p>
    <label for="textfield">Ho Ten:</label>
    <input type="text" name="textfield" id="textfield">
  </p>
  <p>
    <label for="textfield2">Mat Khau:</label>
    <input type="text" name="textfield2" id="textfield2">
  </p>
  <p>
    <label for="textfield3">Nhap ma xac nhan:</label>
    <input type="text" name="maxn" id="maxn"><span><?php echo $capt;?></span>
  </p>
  <p>
    <input type="submit" name="thuchien" id="submit" value="Đăng Nhập">
  </p>
</form>
</body>
</html>

//CAPTCHA: xuly.php
<?php 
session_start();
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_POST['maxn'])&&$_POST['maxn']==$_SESSION['captcha'])
{
echo "Nhập đúng mã xác nhận!";
}
else
echo "Nhập sai mã";
?>
</body>
</html>

PHP#28MySQL#24 - GIỎ HÀNG 3 (xong)

 //datbao.php
<?php
session_start();
if(!isset($_SESSION['giohang'])) $_SESSION['giohang']=array();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<form id="f" name="form1" method="post" action="xuly.php">
  <p>Đăng Ký Đặt Báo
  
  <p>
    <label for="loaibao">Loại báo:</label>
    <select name="loaibao" id="loaibao">
    <?php 
include("connect.php");
$sql="select * from loaibao";
$kq=mysqli_query($link,$sql);
while($d=mysqli_fetch_array($kq))
{

?>
      <option value="<?php echo $d['mabao'];?>"><?php echo $d['tenbao'];?></option>
       <?php }?>
    </select>
  </p>
  <p>
    <label for="soluong">Số lượng:</label>
    <input type="text" name="soluong" id="soluong" value="1">
  </p>
  <p>
    <input type="submit" name="themsp" id="themsp" value="Đưa vào giỏ hàng">
  </p>
</form>
<?php 
//Kiểm tra giỏ hàng có sản phẩm không:
if(count($_SESSION['giohang'])>0)
{
?>

<form method="post" id="form2" name="form2" action="xuly.php">
  <table width="800" border="1" cellspacing="0" cellpadding="0">
    <tbody>
      <tr>
        <th colspan="6" scope="col">Danh sách các loại báo cần đặt</th>
      </tr>
      <tr>
        <th width="64">STT</th>
        <th width="124">Tên Báo</th>
        <th width="70">Giá</th>
        <th width="144">Số lượng</th>
        <th width="321">Thành tiền</th>
        <th width="63">Xóa</th>
      </tr>
      <?php 
  $tong=0;
for($i=0;$i<count($_SESSION['giohang']);$i++)
{
$tong=$tong+$_SESSION['giohang'][$i]['soluong']*$_SESSION['giohang'][$i]['gia'];
  ?>
      <tr>
        <td><?php echo $i+1;?></td>
        <td align="center"><?php echo $_SESSION['giohang'][$i]['tenbao'];?></td>
        <td align="center"><?php echo $_SESSION['giohang'][$i]['gia'];?></td>
        <td align="center"><input name="SL<?php echo $i;?>" type="text" id="SL" value="<?php echo $_SESSION['giohang'][$i]['soluong'];?>" size="5"></td>
        <td align="center"><?php echo $_SESSION['giohang'][$i]['soluong']*$_SESSION['giohang'][$i]['gia'];?></td>
        <td align="center"><a href="xuly.php?xoasp=<?php echo $i;?>">xóa</a></td>
      </tr>
      <?php }?>
      <tr>
        <td colspan="6" align="right">Tổng cộng tiền: <?php echo $tong;?> VNĐ</td>
      </tr>
    </tbody>
  </table>
  <p>
    <input type="submit" name="capnhat" id="capnhat" value="Cập Nhật">
    <input type="button" name="datbao" id="datbao" value="Đặt Báo" onClick="location.href='thongtinkhachhang.php'">
</form>
<?php }?>
</body>

</html>

Saturday, 19 February 2022

PHP#27MySQL#23 - GIỎ HÀNG 1+2

PHẦN 2:

//datbao.php

<?php
session_start();
if(!isset($_SESSION['giohang'])) $_SESSION['giohang']=array();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<form id="f" name="form1" method="post" action="xuly.php">
  <p>Đăng Ký Đặt Báo
  
  <p>
    <label for="loaibao">Loại báo:</label>
    <select name="loaibao" id="loaibao">
    <?php 
include("connect.php");
$sql="select * from loaibao";
$kq=mysqli_query($link,$sql);
while($d=mysqli_fetch_array($kq))
{

?>
      <option value="<?php echo $d['mabao'];?>"><?php echo $d['tenbao'];?></option>
       <?php }?>
    </select>
  </p>
  <p>
    <label for="soluong">Số lượng:</label>
    <input type="text" name="soluong" id="soluong" value="1">
  </p>
  <p>
    <input type="submit" name="themsp" id="themsp" value="Đưa vào giỏ hàng">
  </p>
</form>
<?php 
//Kiểm tra giỏ hàng có sản phẩm không:
if(count($_SESSION['giohang'])>0)
{
?>

<form method="post" id="form2" name="form2" action="">
  <table width="800" border="1" cellspacing="0" cellpadding="0">
    <tbody>
      <tr>
        <th colspan="6" scope="col">Danh sách các loại báo cần đặt</th>
      </tr>
      <tr>
        <th width="64">STT</th>
        <th width="124">Tên Báo</th>
        <th width="70">Giá</th>
        <th width="144">Số lượng</th>
        <th width="321">Thành tiền</th>
        <th width="63">Xóa</th>
      </tr>
      <?php 
  $tong=0;
for($i=0;$i<count($_SESSION['giohang']);$i++)
{
$tong=$tong+$_SESSION['giohang'][$i]['soluong']*$_SESSION['giohang'][$i]['gia'];
  ?>
      <tr>
        <td><?php echo $i+1;?></td>
        <td><?php echo $_SESSION['giohang'][$i]['tenbao'];?></td>
        <td><?php echo $_SESSION['giohang'][$i]['gia'];?></td>
        <td><input type="text" name="SL" id="SL" value="<?php echo $_SESSION['giohang'][$i]['soluong'];?>"></td>
        <td><?php echo $_SESSION['giohang'][$i]['soluong']*$_SESSION['giohang'][$i]['gia'];?></td>
        <td><a href="#">xóa</a></td>
      </tr>
      <?php }?>
      <tr>
        <td colspan="6">Tổng cộng tiền: <?php echo $tong;?> VNĐ</td>
      </tr>
    </tbody>
  </table>
  <p>
    <input type="button" name="capnhat" id="capnhat" value="Cập nhật">
</form>
<?php }?>
</body>
</html>

Thursday, 17 February 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;
}
}
?>

Wednesday, 16 February 2022

PHP#25MySQL#21 - Hướng đối tượng Phần 1 - Xây dựng Hàm - Tin theo Loại - Class

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php 
include("../connect.php");
//Xây dựng hàm: hàm nhận tham số đầu vào là id của 1 loại  và hàm trả về danh sách các tiêu đề tin thuộc loại tin đó:
function tin_loai($idLT)
{
global $link; //biến toàn cục
$sl="select * from tin where idLT=$idLT";
$kq=mysqli_query($link,$sl);
while($d=mysqli_fetch_array($kq))
{
echo $d['TieuDe']."<br/>";
}
}
echo "Các tin của loại tin có id=1: <br/>";
tin_loai(1);
?>
</body>
</html>

PHP#25MySQL#21 - Hướng đối tượng Phần 1 - Xây dựng Hàm

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php 
/*//Xây dựng hàm:
function ten_ham(các_tham_số)
{
//Thân hàm: chứa các lệnh
return giá trị; //có thể có hoặc không
}*/
//Hàm không có return:
function tinhtong($ts1, $ts2)
{
$tam=$ts1+$ts2;
echo "Kết quả là: $tam <br/>";
}
//Gọi hàm:
tinhtong(15,7);
tinhtong(23,48);
//Hàm có return:
function tinhtong2($ts1, $ts2)
{
$tam=$ts1+$ts2;
return $tam;
}
//Gọi hàm : Đối với dạng có return:
$kq1=tinhtong2(57,18);
echo $kq1;
?>
</body>
</html>

Monday, 14 February 2022

PHP#24MySQL#20 Cookie, Xử lý, Ý kiến bạn đọc, bình luận

Saturday, 12 February 2022

PHP#23MySQL#19 - Đăng nhập, Session, Thoát user, Xử lý

Saturday, 22 January 2022

PHP#22MySQL#18 - Xóa, Sửa TIN & admin index (thể loại, loại tin)

//tin.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_GET['lang'])) $lang=$_GET['lang'];
  else $lang="vi";
?>
<form id="form1" name="form1" method="get" action="">
  <p>
    <label for="lang">Ngon ngu:</label>
    <select name="lang" id="lang" onchange="form1.submit()">
      <option value="vi">Viet</option>
      <option value="en" <?php if($lang=="en") echo "selected";?>>English</option>
    </select>
  </p>
  <p>
    <label for="idTL">The loai:</label>
    <select name="idTL" id="idTL" onchange="form1.submit()">
 <?php
  include("../connect.php");
  $sl="select * from theloai where lang='$lang' order by ThuTu";
  $kq=mysqli_query($link,$sl);
$idTL=0;
  while($d=mysqli_fetch_array($kq)){
  if($idTL==0) $idTL=$d['idTL'];
  ?>
      <option value="<?php echo $d['idTL'] ?>" <?php if(isset($_GET['idTL'])&&$_GET['idTL']==$d['idTL']){echo "selected";$idTL=$_GET['idTL'];}?>><?php echo $d['TenTL'] ?></option>
<?php }?>
    </select>
  </p>
  <p>
    <label for="idLT">Loai tin:</label>
    <select name="idLT" id="idLT" onchange="form1.submit()">>
       <?php
  $sl="select * from loaitin where idTL=$idTL order by ThuTu";
  $kq=mysqli_query($link,$sl);
$idLT=0;
  while($d=mysqli_fetch_array($kq)){
  if($idLT==0) $idLT=$d['idLT'];
  ?>
       <option value="<?php echo $d['idLT']; ?>" <?php if(isset($_GET['idLT'])&&$_GET['idLT']==$d['idLT']){echo "selected";$idLT=$_GET['idLT'];}?>><?php echo $d['Ten']; ?></option>
<?php }?>
    </select>
  </p>
</form>
<table width="1000" border="1">
  <tr>
    <td width="40">STT</td>
    <td width="215">Tieu de</td>
    <td width="264">Tom Tat</td>
     <td width="150">Hinh Mo Ta</td>
      <td width="125">Ngay</td>
    <td width="87">Trang Thai</td>
    <td width="73"><a href="tin_them.php?lang=<?php echo $lang;?>&idTL=<?php echo $idTL;?>&idLT=<?php echo $idLT; ?>">Them</a></td>
  </tr>
  <?php
$sltin="select * from tin where idLT=$idLT order by idTin DESC limit 0,5";
$kqtin=mysqli_query($link,$sltin);
while($dtin=mysqli_fetch_array($kqtin))
{ ?>
  <tr>
    <td>1</td>
    <td><?php echo $dtin['TieuDe'];?></td>
    <td><?php echo $dtin['TomTat'];?></td>
    <td><img src="<?php echo $dtin['urlHinh'];?>" width="150" height="100"/></td>
    <td><?php echo date("d-m-Y h:i:s",strtotime($dtin['Ngay']));?></td>
    <td><?php if($dtin['AnHien']) echo "Hiện"; else echo "Ẩn";?></td>
    <td><a href="process.php?xoatin=<?php echo $dtin['idTin'];?>&lang=<?php echo $lang;?>&idTL=<?php echo $idTL;?>&idLT=<?php echo $idLT; ?>" onClick="return confirm('Bạn có chắc chắn xóa tin này không?');">Xoa </a>/ <a href="tin_sua.php?idTin=<?php echo $dtin['idTin'];?>&idTL=<?php echo $idTL;?>">Sua</a></td>
  </tr>
  <?php }?>
</table>
<p>Trang: <a href="#">1</a> &nbsp;</p>
</body>
</html>

Thursday, 20 January 2022

PHP#21MySQL#17 - Upload, Xử lý, Thư viện, chèn Ckeditor

//upload.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta  charset="utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
</head>

<body>
<form action="process.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <p>
    <label for="upImg">Chon anh:</label>
    <input type="file" name="upImg" id="upImg" />
  </p>
  <p>
    <label for="MoTa">Mo ta:</label>
    <textarea name="MoTa" id="MoTa" cols="45" rows="5" class="ckeditor"></textarea>
  </p>
  <p>
    <input type="submit" name="thuchien" id="thuchien" value="Submit" />
  </p>
</form>
<?php
date_default_timezone_set("Asia/Ho_Chi_Minh");
echo date("Y-m-d h:i:s",time());
?>
</body>
</html>

PHP#21MySQL#17 - tin_them.php, process.php - Thêm tin mới, Xử lý tin mới

 //tin_them.php

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
</head>

<body>
<?php
include("../connect.php");
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang='vi';
?>
<form id="form1" name="form1" method="get" action="">
  <p>
    <label for="lang">Ngon ngu:</label>
    <select name="lang" id="lang" onchange="form1.submit();">
      <option value="vi">Viet</option>
      <option value="en" <?php if($lang=='en') echo "selected='selected'";?>>Anh</option>
    </select>
 </p>
 <p>
    <label for="idTL">The loai:</label>
    <select name="idTL" id="idTL" onchange="form1.submit();">
      <?php
  $kq=mysqli_query($link,"select * from theloai where lang='$lang' order by ThuTu");
  $idTL=0;
  while($d=mysqli_fetch_array($kq)){
	  if($idTL==0) $idTL=$d['idTL'];
  ?>
      <option value="<?php echo $d['idTL'];?>" <?php if(isset($_GET['idTL'])&&$d['idTL']==$_GET['idTL']){ echo "selected='selected'"; $idTL=$_GET['idTL'];}?>><?php echo $d['TenTL'];?></option>
      <?php }?>
    </select>
 </p>
 
</form>


<form action="process.php" method="post" enctype="multipart/form-data" name="form2" id="form2">
 <p>
    <label for="idLT">Loai tin:</label>
    <select name="idLT" id="idLT" >
    <?php
	$kqlt=mysqli_query($link,"select * from loaitin where idTL=$idTL order by ThuTu");
	
	while($dlt=mysqli_fetch_array($kqlt)){
		?>  
      <option value="<?php echo $dlt['idLT'];?>"><?php echo $dlt['Ten'];?></option>
<?php }?>
    </select>
  </p>
  <p>
    <label for="TieuDe">Tieu de:</label>
    <input type="text" name="TieuDe" id="TieuDe" />
  </p>
  <p>
    <label for="TieuDe_KhongDau">Tieu de KD:</label>
    <input type="text" name="TieuDe_KhongDau" id="TieuDe_KhongDau" />
  </p>
  <p>
    <label for="TomTat">Tom tat:</label><br/>
    <textarea name="TomTat" id="TomTat" cols="45" rows="5"></textarea>
  </p>
  <p>
    <label for="ufile">Chon hinh:</label>
    <input type="file" name="ufile" id="ufile" />
  </p>
  <p>
    <label for="idSK">Su kien:</label>
    <select name="idSK" id="idSK">
    <?php
	$kqsk=mysqli_query($link,"select * from sukien where lang='$lang' order by ThuTu");
	while($dsk=mysqli_fetch_array($kqsk)){
	?>
      <option value="<?php echo $dsk['idSK'];?>"><?php echo $dsk['MoTa'];?></option>
      <?php }?>
    </select>
  </p>
  <p>
    <label for="Content">Noi dung:</label>
    <textarea name="Content" id="Content" cols="45" rows="5" class="ckeditor"></textarea>
  </p>
  <p>
    <input type="checkbox" name="TinNoiBat" id="TinNoiBat" />
    <label for="TinNoiBat">Noi bat</label>
  </p>
  <p><label>Trang thai:</label>
    <select name="AnHien">
    <option value="0">An</option>
    <option value="1">Hien</option>
    </select>
  </p>
  <p>
  <input type="hidden" name="lang" value="<?php echo $lang;?>"/>
  <input type="hidden" name="idTL" value="<?php echo $idTL;?>"/>
  <input type="submit" name="themtin" id="themtin" value="Them tin" />
    <br />
  </p>
</form>
</body>
</html>

Tuesday, 18 January 2022

PHP#20MySQL#16 - upfiles.php

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form method="post" enctype="multipart/form-data" name="form1" id="form1">
  <input type="hidden" name="MAX_FILE_SIZE" value="102400"/>
  <label for="upfile">File:</label>
  <input type="file" name="upfile" id="upfile">
  <input type="submit" name="submit" id="submit" value="Submit">
</form>
<?php
if(isset($_FILES['upfile']))
{
//Thư mục để chứa file:
$target="files/";
//lấy tên:
$filename=basename($_FILES['upfile']['name']); //abc.jpg đang ở c:/hinh/abc.jpg
$target=$target.$filename;
//kiểm tra file đã có chưa:
if(file_exists($target)) echo "File đã tồn tại!";
else echo "File chưa có!";
//Kiểm tra loại file cần up:
if(preg_match("/\.(jpg|gif|bmp)$/i",$filename))
echo "Đây là file ảnh!";
else echo "Đây không phải file ảnh!";
//up file:
if(move_uploaded_file($_FILES['upfile']['tmp_name'],$target))
echo "$filename đã được up lên thành công!";
else echo "Upload thất bại!";
// size: kích thước của file up lên
//type: kiểu của tập tin:
}
?>
</body>
</html>

PHP#20MySQL#16 - tin.php : Lọc tin theo Ngôn ngữ, Thể loại, Loại & Phân trang

//tin.php
 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
.ht{ font-weight: bold; color:#E80206; font-size:20px;}
</style>
</head>

<body>
<?php
include("../connect.php"); 
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang="vi";
?>
<form method="get" id="form1" name="form1" action="">
  <p>
    <label for="idTL">Ngôn ngữ:</label>
    <select name="lang" id="lang" onChange="form1.submit();">
      <option value="vi">Việt</option>
      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>
    </select>
  </p>
  <p>
    <label for="idTL">Thể loại:</label>
    <select name="idTL" id="idTL" onChange="form1.submit();">
    <?php 
$sl="select * from theloai where lang='$lang' order by ThuTu";
$kq=mysqli_query($link,$sl);
$idTL=0;
while($d=mysqli_fetch_array($kq))
{
if($idTL==0) $idTL=$d['idTL'];
?>
      <option value="<?php echo $d['idTL'];?>"<?php if(isset($_GET['idTL'])&&$_GET['idTL']==$d['idTL']) {echo "selected"; $idTL=$_GET['idTL'];}?>><?php echo $d['TenTL'];?></option>
      <?php }?>
    </select>
  </p>
  <p>
    <label for="idLT">Loại tin:</label>
    <select name="idLT" id="idLT" onChange="form1.submit();">
    <?php 
$sllt="select * from loaitin where idTL=$idTL order by ThuTu";
$kqlt=mysqli_query($link,$sllt);
$idLT=0;
while($dlt=mysqli_fetch_array($kqlt))
{
if($idLT==0) $idLT=$dlt['idLT'];
?>
      <option value="<?php echo $dlt['idLT'];?>"<?php if(isset($_GET['idLT'])&&$_GET['idLT']==$dlt['idLT']) {echo "selected";$idLT=$_GET['idLT'];}?>><?php echo $dlt['Ten'];?></option>
      <?php }?>
    </select>
  </p>
</form>
<table width="776" border="1" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <th width="51" scope="col">STT</th>
      <th width="140" scope="col">Tiêu đề</th>
      <th width="187" scope="col">Tóm tắt</th>
      <th width="120" scope="col">Hình mô tả</th>
      <th width="92" scope="col">Ngày </th>
      <th width="72" scope="col">Trạng thái</th>
      <th width="98" scope="col">Thêm</th>
    </tr>
    <?php
$sl="select * from tin where idLT=$idLT";
$kq=mysqli_query($link,$sl);
$tstin=mysqli_num_rows($kq);
$tin=5;
$tst=ceil($tstin/$tin);
if(isset($_GET['p'])) $p=$_GET['p'];
else $p=1;
$vt=ceil($p-1)*$tin;
 
$sltin="select * from tin where idLT=$idLT order by idTin DESC limit $vt,$tin";
$kqtin=mysqli_query($link,$sltin);
$stt=0;
while($dtin=mysqli_fetch_array($kqtin))
{
$stt++;
?>
    <tr>
      <td><?php echo $stt;?></td>
      <td><?php echo $dtin['TieuDe'];?></td>
      <td><?php echo $dtin['TomTat'];?></td>
      <td><img src="<?php echo $dtin['urlHinh'];?>" width="120" height="100" alt=""/></td>
      <td><?php echo date("d-m-Y h:i:s",strtotime($dtin['Ngay']));?></td>
      <td><?php if($dtin['AnHien']) echo "Hiện"; else echo "Ẩn";?></td>
      <td>Xóa/Sửa</td>
    </tr>
    <?php }?>
  </tbody>
</table>
<p>Trang 
<?php 
for($i=1;$i<=$tst;$i++)
{
if($i==$p) echo "<span class='ht'>".$i."</span>";
else{
?>
<a href="?p=<?php echo $i;?>&lang=<?php echo $lang;?>&idTL=<?php echo $idTL;?>&idLT=<?php echo $idLT;?>"><?php echo $i;?></a> 
<?php }}?>
</p>
</body>
</html>

PHP#20MySQL#16 - Xóa LOẠI TIN

//loaitin.php (phần Xóa)

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Loại Tin</title>

</head>


<body>

<?php

include("../connect.php");

if(isset($_GET['lang'])) $lang=$_GET['lang'];

else $lang="vi";

?>

<form method="get" id="form1" name="form1">

  <p>

    <label for="loaitin">Chọn ngôn ngữ:</label>

    <select name="lang" id="lang" onChange="form1.submit();">

      <option value="vi">Việt</option>

      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>

    </select>

  </p>

  <p>

    <label for="theloai">Thể loại:</label>

    <select name="theloai" id="theloai" onChange="form1.submit();">

<?php 

$sl="select * from theloai where lang='$lang' order by ThuTu";

$kq=mysqli_query($link,$sl);

$idTL=0;

while($d=mysqli_fetch_array($kq))

{

if($idTL==0) $idTL=$d['idTL'];

?>

      <option value="<?php echo $d['idTL'];?>"<?php if(isset($_GET['theloai'])&&$_GET['theloai']==$d['idTL']) {echo "selected"; $idTL=$_GET['theloai'];}?>><?php echo $d['TenTL'];?></option>

      <?php }?>

    </select>

  </p>

</form>

<table width="700" border="1" cellspacing="0" cellpadding="0">

  <tbody>

    <tr>

      <th scope="col">Thứ tự</th>

      <th scope="col">Tên loại</th>

      <th scope="col">Tên không dấu</th>

      <th scope="col">Trạng thái</th>

      <th scope="col"><a href="loaitin_them.php?lang=<?php echo $lang;?>&idTL=<?php echo $idTL;?>">Thêm</a></th>

    </tr>

    <?php 

$sl="select * from loaitin where idTL=$idTL order by ThuTu";

$kq=mysqli_query($link,$sl);

while($d=mysqli_fetch_array($kq)){

?>

    <tr>

      <td><?php echo $d['ThuTu'];?></td>

      <td><?php echo $d['Ten'];?></td>

      <td><?php echo $d['Ten_KhongDau'];?></td>

      <td><?php if($d['AnHien']) echo "Hiện"; else echo "Ẩn";?></td>

      <td><a href="process.php?xoalt=<?php echo $d['idLT']?>&lang=<?php echo $lang;?>&theloai=<?php echo $idTL;?>" onClick="return confirm('Bạn có muốn xóa thể loại này không?')";>Xóa</a>/<a href="loaitin_sua.php?idLT=<?php echo $d['idLT']?>&lang=<?php echo $lang;?>">Sửa</a></td>

    </tr>

    <?php }?>

  </tbody>

</table>

</body>

</html>

Saturday, 15 January 2022

PHP#19MySQL#15 - Loại tin, Thêm, Sửa, Xử lý

//connect.php

<?php 
	$link=@mysqli_connect("localhost","root","") or die("Không tìm thấy Sever");
	mysqli_select_db($link,"tintuc") or die("Không tồn tại DB");
	mysqli_query($link,"set names 'utf8'");
?>

Thursday, 13 January 2022

PHP#18MySQL#14 - Thêm, Xóa, Sửa, Lọc theo ngôn ngữ, lọc theo thể loại, loại

 //theloai.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Thể Loại</title>
</head>

<body>
<?php
include("../connect.php");
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang="vi";
?>
<form method="get" id="form1" name="form1">
  <p>
    <label for="select">Chọn ngôn ngữ:</label>
    <select name="lang" id="lang" onChange="form1.submit();">
      <option value="vi">Việt</option>
      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>
    </select>
  </p>
</form>
<table width="700" border="1" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <th scope="col">Thứ tự</th>
      <th scope="col">Tên thể loại</th>
      <th scope="col">Tên không dấu</th>
      <th scope="col">Trạng thái</th>
      <th scope="col"><a href="theloai_them.php?lang=<?php echo $lang;?>">Thêm</a></th>
    </tr>
    <?php 
$sl="select * from theloai where lang='$lang' order by ThuTu";
$kq=mysqli_query($link,$sl);
while($d=mysqli_fetch_array($kq)){
?>
    <tr>
      <td><?php echo $d['ThuTu'];?></td>
      <td><?php echo $d['TenTL'];?></td>
      <td><?php echo $d['TenTL_KhongDau'];?></td>
      <td><?php if($d['AnHien']) echo "Hiện"; else echo "Ẩn";?></td>
      <td><a href="process.php?xoatl=<?php echo $d['idTL']?>&lang=<?php echo $lang;?>" onClick="return confirm('Bạn có muốn xóa thể loại này không?')";>Xóa</a>/<a href="theloai_sua.php?idTL=<?php echo $d['idTL']?>&lang=<?php echo $lang;?>">Sửa</a></td>
    </tr>
    <?php }?>
  </tbody>
</table>

</body>
</html>

Wednesday, 12 January 2022

PHP#17MySQL#13 - Trang xử lý THÊM dữ liệu (process.php) - Chuyển trang trong PHP: header("location:theloai.php");

<?php 

include("../connect.php");

if(isset($_POST['themtl']))

{

$sl="insert into theloai values(NULL,'{$_POST['lang']}', '{$_POST['TenTL']}', '{$_POST['TenTL_KhongDau']}', {$_POST['ThuTu']}, {$_POST['AnHien']})";

if(mysqli_query($link,$sl))

header("location:theloai.php");

else echo $sl;

}

?>

PHP#17MySQL#13 - Admin/theloai_them.php - $_GET['lang']) sau đó selected ngôn ngữ

 <!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Untitled Document</title>

</head>


<body>

<?php 

if(isset($_GET['lang'])) $lang=$_GET['lang'];

else $lang="vi";

?>

<form method="post" id="form1" name="form1" action="process.php">

  <p>

    <label for="lang">Ngôn ngữ:</label>

    <select name="lang" id="lang">

      <option value="vi">Việt</option>

      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>

    </select>

  </p>

  <p>

    <label for="ThuTu">Thứ tự:</label>

    <input name="ThuTu" type="text" id="ThuTu" size="5">

  </p>

  <p>

    <label for="TenTL">Tên TL:</label>

    <input type="text" name="TenTL" id="TenTL">

  </p>

  <p>

    <label for="TenTL_KhongDau">Tên KD:</label>

    <input type="text" name="TenTL_KhongDau" id="TenTL_KhongDau">

  </p>

  <p>

    <label for="AnHien">Trạng thái:</label>

    <select name="AnHien" id="AnHien">

      <option value="0">Ẩn</option>

      <option value="1">Hiện</option>

    </select>

  </p>

  <p>

    <input type="submit" name="themtl" id="themtl" value="Thêm">

  </p>

</form>

</body>

</html>

PHP#17MySQL#13 - Admin/theloai.php - Lọc thể loại theo ngôn ngữ, selected ngôn ngữ, chuyển trang kèm theo ngôn ngữ

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Thể Loại</title>

</head>


<body>

<p>

<?php 

if(isset($_GET['lang'])) $lang=$_GET['lang'];

else $lang="vi";

?>

 <form id="form1" name="form1" method="get" action="">

  <label for="lang">Chọn ngôn ngữ:</label>

  <select name="lang" id="lang" onChange="form1.submit();">

    <option value="vi">Việt</option>

    <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>

  </select>

 </form>

</p>

<table width="700" border="1" cellspacing="0" cellpadding="0">

  <tbody>

    <tr>

      <th scope="col">Thứ tự</th>

      <th scope="col">Tên thể loại</th>

      <th scope="col">Tên không dấu</th>

      <th scope="col">Trang thái</th>

      <th scope="col"><a href="theloai_them.php?lang=<?php echo $lang;?>">Thêm</a></th>

    </tr>

    <?php

include("../connect.php");

$sl="select * from theloai where lang='$lang' order by ThuTu";

$kq=mysqli_query($link,$sl);

while($d=mysqli_fetch_array($kq)){

?>

    <tr>

      <td><?php echo $d['ThuTu'];?></td>

      <td><?php echo $d['TenTL'];?></td>

      <td><?php echo $d['TenTL_KhongDau'];?></td>

      <td><?php if($d['AnHien']) echo "Hiện"; else echo "Ẩn";?></td>

      <td>Xóa/Sửa</td>

    </tr>

    <?php }?>

  </tbody>

</table>


</body>

</html>

Tuesday, 11 January 2022

PHP#17MySQL#13 - tin cũ hơn

//chitiettin.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_GET['idTin']))
{
$idTin=$_GET['idTin'];
include("connect.php");
$sl="select idLT, TieuDe, TomTat, Content from tin where idTin=$idTin";
$kq=mysqli_query($link,$sl);
$d=mysqli_fetch_array($kq)
?>
<h1 align="center"><?php echo $d['TieuDe'];?></h1>
<div><?php echo $d['TomTat'];?></div>
<div><?php echo $d['Content'];?></div>
<?php }?>
<p>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ũ</p>
<ul>
<?php 
$sltc="select * from tin where AnHien=1 and idLT={$d['idLT']} and idTin < $idTin order by idTin DESC limit 0,5";
$kqtc=mysqli_query($link,$sltc);
while($dtc=mysqli_fetch_array($kqtc)){
?>
<li><a href="index.php?key=ctt&idTin=<?php echo $dtc['idTin'];?>"><?php echo $dtc['TieuDe'];?></a>(<?php echo date("d-m-Y h:i:s",strtotime($dtc['Ngay']));?>)</li><?php }?>
</ul>
</body>
</html>

Saturday, 8 January 2022

PHP#16MySQL#12 - index.php, include

https://app.mediafire.com/fwx971t2bbggr 

//index.php

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Untitled Document</title>

<link href="c2.css" rel="stylesheet" type="text/css">

</head>


<body>

<div id="container">

<div id="header"> </div>

   <div id="thanhmenu"><?php include("menu.php");?></div>

  <div id="main1">

    <div id="main1_1"><?php include("tinnoibat.php");?></div>

<div id="main1_2"><?php include("tinxemnhieu.php");?></div>

<div id="main1_3">  </div>

</div>

<div id="quangcao"> </div>

<div id="main2">

<div id="main2_1">

<?php 

if(isset($_GET['key']))

{

switch($_GET['key'])

{

case "ctt": include("chitiettin.php");break;

case "lt": include("loaitin.php");break;

}

}

else include("tinmoi.php");?></div>

        <div id=main2_2>   

            <div id="loihayydep"> </div>

   <div id="divtimkiem"> </div>

            <div id="divbinhchon"> </div>

   <div id="quangcao2"> </div>

    </div>

</div>

<div id="footer">  </div>

</div> <!-- container -->

</body>

</html>


include chèn vào trong index.php:

//c2.css

@charset "utf-8";

body {

font-family: "Times New Roman", Times, serif;

font-size: 16px;

text-align: center;

}

#container {

margin: auto;

width: 960px;

text-align: left;

}

#header{ height:150px;border:solid 1px #033;background:no-repeat url(banner/banner1.jpg)   

}

#thanhmenu{ height:41px; background-color:#004080;  margin-top:5px; }

#main1_1{ float:left; width:460px; background-color:#9CF; height:300px}

#main1_2{ float:left; width:240px; background-color:#CCC; 

  height:300px; overflow:hidden; margin-left:5px}

#main1_3{

float:left;

width:250px;

margin-left:5px;

height:300px;

background-color: #CCCC99;

#quangcao{ height:90px; margin-top:3px; background-color:#6CC; clear:left   }

#main2_1 {

width:660px;

float:left;

min-height:600px;

background-color: #669999;

}

#main2_2 { width:300px; float:left; background-color:#369;min-height:600px}

#footer{ height:150px; background-color:#036; clear:both; text-align:center; color:#FFFF33; }


#tinxemnhieu p{ 

margin-top:0px; margin-bottom:0px; 

border-bottom:solid 1px #936; white-space:nowrap; 

padding-left:5px; padding-top:6px; padding-bottom:6px;}

#tinxemnhieu a{ text-decoration:none; color:#036; }

#tinxemnhieu a:hover{color:#930}


#tinnoibat{ width:460px}

#tinnoibat #top1 { height:160px; text-align:justify; 

   padding-right:5px; color:#036;  font-size:16px}

#tinnoibat #top1 a { color:#900; text-decoration:none; font-size:18px}

#tinnoibat #top1 a:hover{ color:#F60; text-decoration:underline} 

#tinnoibat #top1 p{ margin-top:0px; margin-bottom:10px}

#tinnoibat #top1 img { margin-right:5px}

#tinnoibat #top3 div { width:33.3%; float:left; text-align:center}

#tinnoibat #top3  a { text-decoration:none; color:#C60}

#tinnoibat #top3  a:hover { text-decoration:underline; color:#069}


#tinmoi .theloai{

font-size:18px;

background-color:#003300;

color:#FFF;

padding-top:5px;

padding-bottom:5px;

clear:left

}

#tinmoi .theloai a{color:#9C0; text-decoration:none; margin-left:5px; font-size:16px;}

#tinmoi .theloai a:hover{ color:#6CC; text-decoration:underline; }

#tinmoi #tinmoinhat {

width:330px;

float:left;

color:#CCCCCC;

height:175px;

overflow:hidden

}

#tinmoi #tinmoinhat p{ text-align:justify; padding-right:5px}

#tinmoi #tinmoinhat a {

text-decoration:none;

color:#CC3333;

font-size:16px;

font-weight:bold

#tinmoi #tinmoinhat a:hover{ text-decoration:underline; color:#C09}


#tinmoi #tinmoitieptheo { float:left; width:330px; height:175px; overflow:hidden; white-space:nowrap  }

#tinmoi #tinmoitieptheo p { margin-top:10px; margin-bottom:10px; padding-left:5px; }

#tinmoi #tinmoitieptheo a{

text-decoration:none;

color:#CC3358

}

#tinmoi #tinmoitieptheo a:hover{text-decoration:underline; color:#C09}


#loihayydep { 

background-color:#036; color:#9C0;padding:10px; 

}

#loihayydep p { margin-top:0px; margin-bottom:10px}

#loihayydep .caption {

color:#6C0; text-transform:uppercase; 

border-bottom:solid 1px #6C0; font-weight:bold; margin-top:0px;

}


#divtimkiem {

background-color: #A7D27B;

padding-top:8px; padding-bottom:8px;}

#divtimkiem #formtimkiem {margin: 0px;}

#divtimkiem #tukhoa {

background: #693; color: #FFFF00;

border: solid 1px #0FF;

padding-top: 4px; padding-bottom: 4px;

width: 225px; margin-left:5px;

}

#divtimkiem #btntimkiem { 

background-color:#CC0000;  color:#00FFCC; 

width:60px;  padding:2px;  border:solid 1px #336699}


#divbinhchon { background-color:#036; color:#9C0;padding:10px;}

#divbinhchon .caption {

color:#6C0; text-transform:uppercase; 

border-bottom:solid 1px #6C0; font-weight:bold; margin-top:0px;

}

#copyright {

display: none;

}

Thursday, 6 January 2022

PHP#15MySQL#11 chèn link, rót dữ liệu, phân trang

//tinmoi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">

#tinmoi {width: 660px;}

#tinmoi .tinmoinhat {
	width:330px;
	float:left;
	color:#336699;
	height: 175px;
	overflow: hidden;
}

#tinmoi .tinmoitieptheo {
	float:left;
	width:329px;
	height: 175px;
	overflow: hidden;
	white-space: nowrap;
	border-left: dotted 1px #030;
}
#tinmoi .theloai {
	font-size:18px; background-color:#003300; color:#FFF;
	padding-top:5px; padding-bottom:5px; clear:left
}
#tinmoi .theloai a {
	color:#9C0; text-decoration:none; margin-left:5px; font-size:16px;}
#tinmoi .theloai a:hover{ color:#6CC; text-decoration:underline; }

#tinmoi  .tinmoinhat a {
	text-decoration:none; color:#003366; 
	font-size:16px; font-weight:bold; 
}
#tinmoi .tinmoinhat a:hover{ text-decoration:underline; color:#C09}
#tinmoi .tinmoinhat img {	margin-right: 5px; }

#tinmoi .tinmoitieptheo a {
	text-decoration:none;
	color:#003333
}
#tinmoi .tinmoitieptheo a:hover{text-decoration:underline; color:#C09}
#tinmoi .tinmoitieptheo p {
	margin-top:10px; margin-bottom:10px; padding-left:5px;
}

</style>
</head>

<body>
<div id="tinmoi">
<?php 
	include('connect.php');
	$sl="select * from theloai where lang='vi' and AnHien=1 order by ThuTu ASC";
	$kq=mysqli_query($link,$sl);
	while($d=mysqli_fetch_array($kq))
	{
?>
  <div class="theloai"> <?php echo $d['TenTL'];

  $sl2="select * from loaitin where idTL={$d['idTL']} order by ThuTu ASC";
  $kq2=mysqli_query($link,$sl2);
  while($d2=mysqli_fetch_array($kq2))
  {
  ?> 
      <a href="loaitin.php?idLT=<?php echo $d2['idLT'];?>"> <?php echo $d2['Ten'];?>  </a> <?php }?>
  </div>

  <!-- div theloai -->
  
  <?php 
  	$sltin="select * from tin where idLT in (select idLT from loaitin where idTL={$d['idTL']} and AnHien=1) and AnHien=1 order by idTin DESC limit 0,6";
	$kqtin=mysqli_query($link,$sltin);
	$dtin=mysqli_fetch_array($kqtin);
  ?>
  <div class="tinmoinhat">

    <a href="chitiettin.php?idtin=<?php echo $dtin['idTin'];?>"> <?php echo $dtin['TieuDe'];?> </a>
    <p> <img src="<?php echo $dtin['urlHinh'];?>" width="80" height="80" align="left" />
      <?php echo $dtin['TomTat'];?>      
    </p>
  </div> <!-- tinmoinhat -->
  <div class="tinmoitieptheo">
  <?php 
  while($dtin=mysqli_fetch_array($kqtin)){
  ?>
    <p> <a href="chitiettin.php?idtin=<?php echo $dtin['idTin'];?>"> <?php echo $dtin['TieuDe'];?>  </a> </p>	<?php }?>
  </div>  <!-- div id=tinmoitieptheo -->
  <?php }?>
  


</div><!-- tinmoi -->


</body>
</html>

Tuesday, 4 January 2022

PHP#14MySQL#10 - Slider (Chính thức làm web)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Featured Content Slider Using jQuery - Web Developer Plus  Demos</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.min.js" ></script>
<script type="text/javascript" src="jquery-ui.min.js" ></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 3000, true);
	});
</script>
</head>
<body>


		<h3>&raquo; Featured Content Slider Using jQuery</h3>
		
		<div id="featured" >
		  <ul class="ui-tabs-nav">
          <?php 
		  	include("../connect.php");
			$sl="select * from slider";
			$kq=mysqli_query($link,$sl);
			$i=0;
			while($d=mysqli_fetch_array($kq))
			{
		  ?>
	        <li class="ui-tabs-nav-item<?php if($i==0) echo " ui-tabs-selected"; $i=1;?>" id="nav-fragment-<?php echo $d['id'];?>">
            	<a href="#fragment-<?php echo $d['id'];?>">
                	<img src="images/<?php echo $d['hinhnho'];?>" alt="" />
                	<span><?php echo $d['tieude'];?></span>
                 </a>
            </li>
	        <?php }?>
	      </ul>

	    

	    <!-- Second Content -->
        <?php 
			$kq=mysqli_query($link,$sl);
			$i=0;
			while($d=mysqli_fetch_array($kq))
			{
		?>
	    <div id="fragment-<?php echo $d['id'];?>" class="ui-tabs-panel<?php if($i>0) echo " ui-tabs-hide";$i=1;?>" style="">
			<img src="images/<?php echo $d['hinhlon'];?>" alt="" />
			 <div class="info" >
				<h2><a href="#" ><?php echo $d['tieude'];?></a></h2>
				<p><?php echo $d['mota'];?>....
                    <a href="#" >đọc thêm</a>
                </p>
			 </div>
	    </div>
		<?php }?>
	    

	    


	</div>


</body>
</html>

PHP#14MySQL#10 - tintuc.sql - Menu (Chính thức làm web tin tức) tinxemnhieu.php , tinnoibat.php, tinmoi.php

//tinxemnhieu.php

<style type="text/css">
<!--
#tinxemnhieu {
	width: 250px;
	border: 1px solid #0099CC;
	overflow: hidden;
	white-space: nowrap;
}
#tinxemnhieu  h4 {
	background-color: #0099CC;
	margin-top: 0px;
	margin-bottom: 0px;
	padding-top: 5px;
	padding-bottom: 5px;
	padding-left: 10px;
	color: #FFFF00;
}
#tinxemnhieu a {
	color: #CC3399;
	text-decoration: none;
}
#tinxemnhieu a:hover {
	color: #FFCC00;
}
#tinxemnhieu p {
	margin-top: 0px;
	margin-bottom: -1px;
	background-color: #FFFFCC;
	padding-top: 5px;
	padding-bottom: 5px;
	padding-left: 10px;
	border: 1px solid #0099CC;
}
-->
</style>


<div id="tinxemnhieu">
<h4>TIN XEM NHIỀU</h4>
<?php 
	$link=@mysqli_connect("localhost","root","") or die("Không tìm thấy Sever");
	mysqli_select_db($link,"tintuc") or die("Không tồn tại DB");
	mysqli_query($link,"set names 'utf8'");
	$sl="select * from tin  WHERE lang='vi' and AnHien=1 order by SoLanXem DESC limit 0,10";
	$kq=mysqli_query($link,$sl);
	while($d=mysqli_fetch_array($kq))
	{
?>
<p> <a href="#"> <?php echo $d['TieuDe'];?> </a>  </p>
<?php }?>
</div>

Thursday, 30 December 2021

PHP#13MySQL#9 - TabsMenu

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="60" colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" bgcolor="#FF9933">
    <!--Links used to initiate the sub menus. Pass in the desired submenu index numbers (ie: 0, 1) -->
 <?php
		include("../connect.php");
		$sl1="select idTL, TenTL from theloai";
		$kq1=mysqli_query($link,$sl1);
		$i=0;
		while($d1=mysqli_fetch_array($kq1))
		{ if($i>0){echo " | ";}
		  $i=1;
		?>
		<a href="#" onMouseover="showit(<?php echo $d1['idTL'];?>)"><?php echo $d1['TenTL'];?></a>
	<?php }?>



<br>

<!-- Edit the dimensions of the below, plus background color-->
<ilayer width=400 height=32 name="dep1" bgColor="#E6E6FF">
<layer name="dep2" width=400 height=32>
</layer>
</ilayer>
<div id="describe" style="background-color:#E6E6FF;width:100%;height:20px" onMouseover="clear_delayhide()" onMouseout="resetit(event)"></div>


<script language="JavaScript1.2">

/*
Tabs Menu (mouseover)- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var submenu=new Array()

//Set submenu contents. Expand as needed. For each content, make sure everything exists on ONE LINE. Otherwise, there will be JS errors.
<?php
$kq1=mysqli_query($link,$sl1);
while($d1=mysqli_fetch_array($kq1))
	{
?>
submenu[<?php echo $d1['idTL'];?>]='<font size="2" face="Verdana"><b><?php 
	$sl2="select Ten from loaitin where idTL=".$d1['idTL']	;
			$kq2=mysqli_query($link,$sl2);
			while($d2=mysqli_fetch_array($kq2)){
	?> | <a href="#"><?php echo $d2['Ten'];?></a><?php }?></b></font>'
<?php }?>

//Set delay before submenu disappears after mouse moves out of it (in milliseconds)
var delay_hide=500

/////No need to edit beyond here

var menuobj=document.getElementById? document.getElementById("describe") : document.all? document.all.describe : document.layers? document.dep1.document.dep2 : ""

function showit(which){
clear_delayhide()
thecontent=(which==-1)? "" : submenu[which]
if (document.getElementById||document.all)
menuobj.innerHTML=thecontent
else if (document.layers){
menuobj.document.write(thecontent)
menuobj.document.close()
}
}

function resetit(e){
if (document.all&&!menuobj.contains(e.toElement))
delayhide=setTimeout("showit(-1)",delay_hide)
else if (document.getElementById&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhide=setTimeout("showit(-1)",delay_hide)
}

function clear_delayhide(){
if (window.delayhide)
clearTimeout(delayhide)
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

</script>
</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>