Skip to main content

(Phân trang) Liên kết trang $_GET, hiện dữ liệu và phân trang tại trang khác WHERE , LIMIT

Database: https://drive.google.com/file/d/16mUt4iNR-FOraT1NAjtpXkPJVh3tPaiY/view

Hình ảnh: https://drive.google.com/file/d/19hJroj8BNEVV4_osAo2eXHspMciJb6LA/view

//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'");

?>


// loaisp_duc.php

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>loaisp_duc</title>

</head>


<body>

<?php

include("connect.php");

$sl="select * from webtm_loaisp";

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

while($d=mysqli_fetch_array($kq))

{

echo "<p><a href='pt_loai_duc.php?idLoai={$d['idLoai']}'>{$d['TenLoai']}</a></p>";

}

?>

</body>

</html>

//pt_loai_duc.php

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>pt_loai_duc</title>

<style>

.ht{font-size: 20px; color: #F10C0F; font-weight: bold;}

</style>

</head>


<body>

<?php

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

{

$idLoai=$_GET['idLoai'];

    include("connect.php");

$sp=5;

$sl="select TenSP, UrlHinh, Gia from webtm_sanpham where idLoai=$idLoai";

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

$tsp=mysqli_num_rows($kq);

$tst=ceil($tsp/$sp);

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

else $p=1;

$vt=($p-1)*$sp;

$slsp="select TenSP, UrlHinh, Gia from webtm_sanpham where idLoai=$idLoai limit $vt,$sp";

$kqsp=mysqli_query($link,$slsp);

?>

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

  <tbody>

    <tr>

      <th scope="col">STT</th>

      <th scope="col">Tên sản phẩm</th>

      <th scope="col">Hình</th>

      <th scope="col">Giá</th>

    </tr>

    <?php

$stt=1;

    while($dsp=mysqli_fetch_array($kqsp))

{

?>

    <tr>

      <td><?php echo $stt++;?></td>

      <td><?php echo $dsp['TenSP'];?></td>

      <td><img src="<?php echo $dsp['UrlHinh'];?>" width="70" alt=""/></td>

      <td><?php echo $dsp['Gia'];?></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="pt_loai_duc.php?p=<?php echo $i;?>&idLoai=<?php echo $idLoai;?>"><?php echo $i;?></a> <?php } }?></p>


<?php }?>

</body>

</html>

Comments

Popular posts from this blog

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 o...

2 (giao diện Visual C#) Solution Explorer

Bài 2 - SOME OTHER TIME - Vào dịp khác