Skip to main content

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($link,$slsp);
while($d=mysqli_fetch_array($kqsp))
{ ?>
<div class="sanpham">
<p><img src="<?php echo $d['UrlHinh'];?>" width="120"/></p>
<p><?php echo $d['TenSP'];?> <br/><?php echo $d['Gia'];?></p>
</div>
<?php }?>
<div style="clear: left;" > <p>Trang <?php for($i=1;$i<=$tst;$i++){
if($i==$p)
echo "<span class='ht'>".$i."</span> ";
else{
?><a href="pt_pc.php?p=<?php echo $i;?>"><?php echo $i;?></a> <?php } }?></p> </div>
</div>
</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