Friday, 17 December 2021

theloaibh.php, dsbh.php - PHP#9MySQL#5 - bắt đối tượng khi click, liên kết qua trang khác để hiện thị nội dung tương ứng $_GET[' '] trong PHP

 //connect.php

<?php
//Kết nối đến server DB:
	$link=@mysqli_connect("localhost","root","") or die("Không thể kết nối đến Server!");
	//Chọn database cần thao tác:
	mysqli_select_db($link,"webtintuc") or die("Không tồn tại DB này!");
	mysqli_query($link,"set names 'utf8'");
?>

//theloaibh.php
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>theloaibh.php</title>
  </head>
  <body>
    <?php
		include("connect.php");
		$sl="select * from webnhac_theloai";
		$kq=mysqli_query($link,$sl);
		while($d=mysqli_fetch_array($kq))
		{
	?>
    <p><a href="dsbh.php?idTL=<?php echo $d['idTL'];?>"><?php echo $d['TenTL'];?></a></p>
    <?php } ?>
  </body>
</html>

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

<body>
<?php
if(isset($_GET['idTL']))
{
	$idTL=$_GET['idTL'];
	include("connect.php");
	$sl="select idTL, TenBH from webnhac_baihat where idTL=$idTL";
	$kq=mysqli_query($link,$sl);
	while($d=mysqli_fetch_array($kq)){
?>
<p><?php echo $d['TenBH']; ?></p>
<?php }}?>
</body>

0 comments:

Post a Comment