Skip to main content

Posts

Showing posts from December 25, 2021

PHP#12MySQL#8 - Phân Trang - Phân Nhóm (RẤT QUAN TRỌNG) n=ceil(p/sn) //p=(n-1)sn+1 //Lần đầu chạy lên p=n=1 //$dau=($n-1)*$sn+1; $cuoi=$n*$sn

<!doctype html> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> .ht{font-size: 20px; color: #F10C0F; font-weight: bold;} </style> </head> <body> <?php include("connect.php"); //Quy ước 1 trang gồm 5sp: $sp=5; //Quy ước 1 nhóm gồm 5 trang: $sn=5; //Truy vấn lấy tất cả sản phẩm: $sl="select TenSP, UrlHinh, Gia from webtm_sanpham"; $kq=mysqli_query($link,$sl); //tính tổng sản phẩm: $tsp=mysqli_num_rows($kq); //Tính tổng số trang: $tst=ceil($tsp/$sp); //Tính tổng số nhóm: $tsn=ceil($tst/$sn); //Tính nhóm, trang hiện tại: if(isset($_GET['p'])) {$p=$_GET['p']; $n=ceil($p/$sn);} else if(isset($_GET['n'])){$n=$_GET['n'];$p=($n-1)*$sn+1;} else $p=$n=1; //Tính vị trí cần để lấy sản phẩm: $vt=($p-1)*$sp; $slsp="select TenSP, UrlHinh, Gia from webtm_sanpham limit $vt,$sp"; $kqsp=mys...

PHP#12MySQL#8 - Phân Trang - Phân Cột

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> #ds_sp{width: 650px; margin: auto;} .sanpham{width: 120px; float: left; height: 250px; border: 1px #4D3BE5 solid; margin-right: 2px; margin-bottom: 2px;} .ht{font-size: 20px; color: #F10C0F; font-weight: bold;} </style> </head> <body> <div id="ds_sp"> <?php include("connect.php"); //Quy ước 1 trang gồm 20sp: $sp=5*4; //Truy vấn lấy tất cả sản phẩm: $sl="select TenSP, UrlHinh, Gia from webtm_sanpham"; $kq=mysqli_query($link,$sl); //tính tổng sản phẩm: $tsp=mysqli_num_rows($kq); //Tính tổng số trang: $tst=ceil($tsp/$sp); //Tính trang hiện tại: if(isset($_GET['p'])) $p=$_GET['p']; else $p=1; //Tính vị trí cần để lấy sản phẩm: $vt=($p-1)*$sp; $slsp="select TenSP, UrlHinh, Gia from webtm_sanpham limit $vt,$sp"; $kqsp=mysqli_query($l...