Skip to main content

Posts

Sản phẩm mới, Sản phẩm xem nhiều, Tất cả sản phẩm, Phân trang-Phân nhóm

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Mới Nhất, Xem Nhiều</title> <style> #ds_sp{ width:620px; margin:auto;} .sanpham{ width:120px; float:left; border:1px #2802E9 solid; margin-right:2px; margin-bottom:2px;} .tieude{ font-size:20px; font-weight:bold; background-color: #230DE0; color:#F5EFEF; margin-top:10px; margin-bottom:10px;} .ht{ font-size:20px; color:#E0070B; font-weight:bold;} </style> </head> <body> <?php $link=@mysqli_connect("localhost","root","") or die("Không tìm thấy Sever"); mysqli_select_db($link,"webtintuc") or die("Không tồn tại DB"); mysqli_query($link,"set names 'utf8'"); $sp=5*4; $sn=5; $sl="select TenSP, UrlHinh, Gia from webtm_sanpham"; $kq=mysqli_query($link,$sl); $tsp=mysqli_num_rows($kq); $tst=ceil($tsp/$sp); $tsn=ceil($tst/$sn); if(isset($_GET['p'])){$p=$_GET...

Sản phẩm mới, Sản phẩm xem nhiều

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> #ds_sp{width: 620px; 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;} .tieude{ background-color:#0A16F0; font-size:20px; font-weight:bold; margin-bottom:10px; margin-top:10px; width:100%; color:#F5F3F3;} </style> </head> <body> <div id="ds_sp"> <div class="tieude">Sản Phẩm Mới</div> <?php include("connect.php"); //Quy ước 1 trang gồm 20sp: $sp=5*2; //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[...

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

Kết hợp LỌC + PHÂN TRANG chungloaisp, loaisp, sanpham

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> .ht{ font-size:20px; color:#F40408; font-weight:bold;} </style> </head> <body> <form method="get" id="form1" name="form1"> <p> <label>Chủng loại sp: </label> <select name="chungloai" id="chungloai" onChange="form1.submit();"> <?php $link=@mysqli_connect("localhost","root","") or die ("Không tìm thấy Sever"); mysqli_select_db($link,"webtintuc") or die("Không tồn tại DB"); mysqli_query($link,"set names 'utf8'"); $sl="select * from webtm_chungloaisp"; $kq=mysqli_query($link,$sl); $idCL=0; if(isset($_GET['chungloai'])) $idCL=$_GET['chungloai']; while($d=mysqli_fetch_array($kq)) { if($idCL==0) $idCL=$d['idCL']; ?>...

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

(Phân trang) cần đếm Tổngsốsảnphẩm, Tổngsốtrang, truyền tham số Trang, tính Vịtrí (dựa vào tham số Trang) $vt=($p-1)*$sp

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'"); ?> //phantrang_duc.php?p="sốtrang" <!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"); $sp=5; echo "Sản phẩm mỗi trang: ".$sp; $sl="select TenSP, UrlHinh, Gia from webtm_sanpham"; $kq=mysqli_query($...