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

Wednesday, February 16, 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, February 14, 2022

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

Saturday, February 12, 2022

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

Saturday, January 22, 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>


//tin_sua.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
if(isset($_GET['idTin']))
{
$idTin=$_GET['idTin'];
include("../connect.php");
$kqtin=mysqli_query($link,"select * from tin where idTin=$idTin");
$dtin=mysqli_fetch_array($kqtin);
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang=$dtin['lang'];
?>
<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>
 
    <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>
 <input type="hidden" name="idTin" value="<?php echo $dtin['idTin'];?>"/>
</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 if($dtin['idLT']==$dlt['idLT']) echo "selected='selected'";?>><?php echo $dlt['Ten'];?></option>
<?php }?>
    </select>
  </p>
  <p>
    <label for="TieuDe">Tieu de:</label>
    <input type="text" name="TieuDe" id="TieuDe" value="<?php echo $dtin['TieuDe'];?>" />
  </p>
  <p>
    <label for="TieuDe_KhongDau">Tieu de KD:</label>
    <input type="text" name="TieuDe_KhongDau" id="TieuDe_KhongDau" value="<?php echo $dtin['TieuDe_KhongDau'];?>" />
  </p>
  <p>
    <label for="TomTat">Tom tat:</label>
    <textarea name="TomTat" id="TomTat" cols="45" rows="5"><?php echo $dtin['TomTat'];?></textarea>
  </p>
  <p>
    <label for="ufile">Chon hinh:</label>
    <input type="file" name="ufile" id="ufile" /> <img src="<?php echo $dtin['urlHinh'];?>" width="100"/>
  </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 if($dtin['idSK']==$dsk['idSK']) echo "selected='selected'";?>><?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"><?php echo $dtin['Content'];?></textarea>
  </p>
  <p>
    <input type="checkbox" name="TinNoiBat" id="TinNoiBat" <?php if($dtin['TinNoiBat']) echo "checked='checked'";?>/>
    <label for="TinNoiBat">Noi bat</label>
  </p>
   <p><label>Trang thai:</label>
    <select name="AnHien">
    <option value="0">An</option>
    <option value="1" <?php if($dtin['AnHien']) echo "selected='selected'";?>>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="hidden" name="idTin" value="<?php echo $dtin['idTin'];?>"/>
    <input type="submit" name="suatin" id="suatin" value="Cap nhat tin" />
    <br />
  </p>
</form>
<p>&nbsp;</p>
<?php }?>
</body>
</html>

Thursday, January 20, 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>

//process.php

<?php
if(isset($_FILES['upImg']))
{
//Thư mục để chứa file:
$target="files/";
//lấy tên:
$filename=basename($_FILES['upImg']['name']); //abc.jpg đang ở c:/hinh/abc.jpg
$target=$target.$filename;

//up file:
if(move_uploaded_file($_FILES['upImg']['tmp_name'],$target))
{
//Thêm thông tin vào bảng dữ liệu images:
include("../connect.php");
$sl="insert into images values(NULL, '{$_POST['MoTa']}', '$target' )";
if(mysqli_query($link,$sl))
header("location:thuvien.php");
else
{
echo $sl;
//Xóa 1 file:
unlink($target);
}
}
else echo "Upload thất bại!";
}
?>

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>

//process.php
<?php
include("../connect.php");
date_default_timezone_set("Asia/Ho_Chi_Minh");
//Xử lý thêm 1 thể loại mới:
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?lang=".$_POST['lang']);
else echo $sl;
}
//Xử lý cập nhật 1 thể loại:
if(isset($_POST['suatl']))
{
$sl="update theloai set lang='{$_POST['lang']}', TenTL='{$_POST['TenTL']}', TenTL_KhongDau='{$_POST['TenTL_KhongDau']}', ThuTu={$_POST['ThuTu']}, AnHien={$_POST['AnHien']} where idTL={$_POST['idTL']}";
if(mysqli_query($link,$sl))
header("location:theloai.php?lang=".$_POST['lang']);
else echo $sl;
}

// Xử lý xóa 1 thể loai
if(isset($_GET['xoatl']))
{
$sl="delete from theloai where idTL=".$_GET['xoatl'];
if(mysqli_query($link,$sl))
header("location:theloai.php?lang=".$_GET['lang']);
else echo $sl;
}

//Xử lý thêm 1 loại tin mới:
if(isset($_POST['them_lt']))
{
$sl="insert into loaitin values(NULL, '{$_POST['lang']}', '{$_POST['Ten']}', '{$_POST['Ten_KhongDau']}', {$_POST['ThuTu']}, {$_POST['AnHien']}, {$_POST['idTL']})";
if(mysqli_query($link,$sl))
header("location:loaitin.php?lang=".$_POST['lang']."&theloai=".$_POST['idTL']);
else echo $sl;
}

//Xử lý cập nhật 1 loại tin:
if(isset($_POST['sua_lt']))
{
$sl="update loaitin set lang='{$_POST['lang']}', Ten='{$_POST['Ten']}', Ten_KhongDau='{$_POST['Ten_KhongDau']}', ThuTu={$_POST['ThuTu']}, AnHien={$_POST['AnHien']}, idTL={$_POST['idTL']} where idLT={$_POST['idLT']}";
if(mysqli_query($link,$sl))
header("location:loaitin.php?lang=".$_POST['lang']."&theloai=".$_POST['idTL']);
else echo $sl;
}

//Xử lý xóa 1 loại tin:
if(isset($_GET['xoalt']))
{
$sl="delete from loaitin where idLT=".$_GET['xoalt'];
if(mysqli_query($link,$sl))
header("location:loaitin.php?lang=".$_GET['lang']."&theloai=".$_GET['idTL']);
else echo $sl;
}
//Xử lý thêm 1 tin mới:
if(isset($_POST['themtin']))
{
//Xử lý upfile:
if(isset($_FILES['ufile']))
{
$target="../dataupload/images/";
$filename=basename($_FILES['ufile']['name']);
$target.=$filename;
if(move_uploaded_file($_FILES['ufile']['tmp_name'],$target))
{
$url="/tintuc/dataupload/images/".$filename;
$ngay=date("Y-m-d h:i:s",time());
if(isset($_POST['TinNoiBat'])&&$_POST['TinNoiBat']=="on")
$tnb=1;
else $tnb=0;

//thêm dữ liệu vào bảng tin:
$sl="insert into tin values(NULL, '{$_POST['lang']}', '{$_POST['TieuDe']}', '{$_POST['TieuDe_KhongDau']}', '{$_POST['TomTat']}', '$url', '$ngay', 1, {$_POST['idSK']}, '{$_POST['Content']}', {$_POST['idLT']}, 0, $tnb, {$_POST['AnHien']})";
if(mysqli_query($link,$sl))
header("location:tin.php?lang=".$_POST['lang']."&idTL=".$_POST['idTL']."&idLT=".$_POST['idLT']);
else
{echo $sl; unlink($target);}
}
else echo "upload thất bại!";
}
}
?>

Tuesday, January 18, 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>