Skip to content

Commit 77325eb

Browse files
committed
almost done
1 parent 5a62662 commit 77325eb

File tree

7 files changed

+99
-99
lines changed

7 files changed

+99
-99
lines changed

admin/user/xem.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
<td><?php echo $user['idUser']; ?></td>
2626
<td><?php echo $user['HoTen']; ?></td>
2727
<td><?php echo $user['Email']; ?></td>
28-
<td><?php if(strlen($user['DiaChi']) > 30) echo substr($user['DiaChi'], 0 , strpos($user['DiaChi'], ' ', 25))."...<i class='glyphicon glyphicon glyphicon-plus-sign'></i>"; else echo $user['DiaChi']; ?></td>
28+
<td>
29+
<span title='<?php echo $user['DiaChi'];?>'>
30+
<?php if(strlen($user['DiaChi']) > 30) echo substr($user['DiaChi'], 0 , strpos($user['DiaChi'], ' ', 25))."...<i class='glyphicon glyphicon glyphicon-plus-sign'></i>"; else echo $user['DiaChi']; ?>
31+
</span>
32+
</td>
2933
<td><?php echo $user['DienThoai']; ?></td>
3034
<td><?php echo date("d-my-Y", strtotime($user['NgayDangKy'])); ?></td>
3135
<td><?php if($user['idGroup'] == 1) echo "Admin"; else echo "User"; ?></td>

classSP.php

Lines changed: 49 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,48 @@ public function laydsloaisp($idCL){
2929
return $data;
3030
}
3131

32-
public function laysptheoid($id){
32+
public function laydssanpham($idCL, $idLoai, $gia, $order, &$totalrows, $current_page=1, $per_page=5){
33+
settype($idCL, "int"); settype($idloai, "int");
34+
35+
if($idCL == 0) return false;
36+
if($idLoai == 0) $idLoai = ''; else $idLoai = "AND idLoai=$idLoai";
37+
38+
39+
$min = 0; $max = 0;
40+
$gia = explode("-", $gia);
41+
if(count($gia) == 2){
42+
$min = $gia[0]; $max = $gia[1];
43+
settype($min, "int"); settype($max, "int");
44+
}
45+
if($min == 0) $min = ''; else $min = "AND Gia>=$min";
46+
if($max == 0) $max = ''; else $max = "AND Gia <=$max";
47+
48+
$this->db->escape_string($order);
49+
if($order == 'giatangdan') $order = 'Gia ASC';
50+
elseif($order == 'spmoi') $order = 'NgayCapNhat DESC';
51+
elseif($order == 'banchay') $order = 'SoLanMua DESC';
52+
else $order = 'Gia DESC';
53+
54+
$sql = "SELECT count(idSP) FROM sanpham WHERE idCL=$idCL $idLoai $min $max AND AnHien=1 ORDER BY $order";
55+
if(!$result = $this->db->query($sql)) die("loi ket noi");
56+
if($result->num_rows < 1) echo $sql;
57+
$row = $result->fetch_array();
58+
$totalrows = $row[0];
3359

60+
if($current_page < 1) $current_page=1;
61+
$start = ceil($current_page-1)*$per_page;
62+
63+
$sql = "SELECT idCL, idLoai, idSP, TenSP, Gia, urlHinh, SoLanMua FROM sanpham WHERE idCL=$idCL $idLoai $min $max AND AnHien=1 ORDER BY $order limit $start, $per_page";
64+
if(!$result = $this->db->query($sql)) die("loi ket noi");
65+
66+
$data = array();
67+
while($row = $result->fetch_assoc()){
68+
$data[] = $row;
69+
}
70+
return $data;
71+
}
72+
73+
public function laysptheoid($id){
3474
if($id <= 0) header('location: index.php');
3575

3676
$sql = "select * from sanpham where idSP=$id";
@@ -102,47 +142,28 @@ public function layvideo($idSP){
102142
return $row[0];
103143
}
104144

105-
public function laydssanpham($idCL, $idLoai, $gia, $order, &$totalrows, $current_page=1, $per_page=5){
106-
settype($idCL, "int"); settype($idloai, "int");
107-
108-
if($idCL == 0) return false;
109-
if($idLoai == 0) $idLoai = ''; else $idLoai = "AND idLoai=$idLoai";
110-
111-
112-
$min = 0; $max = 0;
113-
$gia = explode("-", $gia);
114-
if(count($gia) == 2){
115-
$min = $gia[0]; $max = $gia[1];
116-
settype($min, "int"); settype($max, "int");
117-
}
118-
if($min == 0) $min = ''; else $min = "AND Gia>=$min";
119-
if($max == 0) $max = ''; else $max = "AND Gia <=$max";
145+
public function timkiemsanpham($keyword, &$totalrows, $current_page=1, $per_page=5){
146+
$keyword = trim($keyword);
147+
$keyword = $this->db->escape_string($keyword);
148+
if(empty($keyword)){ header("location: index.php"); return false;}
120149

121-
$this->db->escape_string($order);
122-
if($order == 'giatangdan') $order = 'Gia ASC';
123-
elseif($order == 'spmoi') $order = 'NgayCapNhat DESC';
124-
elseif($order == 'banchay') $order = 'SoLanMua DESC';
125-
else $order = 'Gia DESC';
126-
127-
$sql = "SELECT count(idSP) FROM sanpham WHERE idCL=$idCL $idLoai $min $max AND AnHien=1 ORDER BY $order";
150+
$sql = "SELECT count(idSP) FROM sanpham WHERE TenSP LIKE '%$keyword%'";
128151
if(!$result = $this->db->query($sql)) die("loi ket noi");
129-
if($result->num_rows < 1) echo $sql;
130-
$row = $result->fetch_array();
152+
$row = $result->fetch_row();
131153
$totalrows = $row[0];
132154

133-
if($current_page < 1) $current_page=1;
134155
$start = ceil($current_page-1)*$per_page;
135156

136-
$sql = "SELECT idCL, idLoai, idSP, TenSP, Gia, urlHinh, SoLanMua FROM sanpham WHERE idCL=$idCL $idLoai $min $max AND AnHien=1 ORDER BY $order limit $start, $per_page";
157+
$sql = "SELECT idCL, idLoai, idSP, TenSP, Gia, urlHinh, SoLanMua FROM sanpham WHERE TenSP LIKE '%$keyword%' ORDER BY TenSP LIMIT $start, $per_page";
137158
if(!$result = $this->db->query($sql)) die("loi ket noi");
138-
139159
$data = array();
140160
while($row = $result->fetch_assoc()){
141161
$data[] = $row;
142162
}
143163
return $data;
144164
}
145165

166+
146167
public function thanhphantrang($url, $totalrows, $current_page, $per_page=5, $pages_per_group=5){
147168
if($totalrows <= $per_page) return false;
148169

@@ -323,69 +344,4 @@ public function binhluan(){
323344
if(!$result = $this->db->query($sql)) die($sql);
324345
header("location: index.php?chungloai={$_POST['chungloai']}&loaisp={$_POST['loaisp']}&idSP={$_POST['idSP']}#binhluan");
325346
}
326-
327-
// public function test(){
328-
// $sql = "select idSP FROM sanpham";
329-
// $result = $this->db->query($sql);
330-
// while($row = $result->fetch_row()){
331-
// $listID[] = $row[0];
332-
// }
333-
//
334-
// foreach($listID as $idSP){
335-
// $sql = "INSERT INTO sanpham_comment (idSP, hoten, email, noidung, ngay_comment)
336-
// VALUES ($idSP, 'teo', '[email protected]', 'test comment test comment test comment test comment test comment test comment test comment test comment test comment test comment ', '2016-05-09')";
337-
// $this->db->query($sql);
338-
// }
339-
// }
340-
341-
// public function gia(){
342-
// $sql = "select idSP from sanpham";
343-
// $result = $this->db->query($sql);
344-
//
345-
// $ids = array();
346-
// while($row= $result->fetch_row()){
347-
// $ids[] = $row[0];
348-
// }
349-
//
350-
// foreach($ids as $idSP){
351-
// $num = rand(5, 200);
352-
// $gia = $num*100000;
353-
// $sql = "update sanpham set Gia=$gia where idSP=$idSP";
354-
// $this->db->query($sql);
355-
// }
356-
// }
357-
358-
// public function solanxem(){
359-
// $sql = "select idSP from sanpham";
360-
// $result = $this->db->query($sql);
361-
//
362-
// $ids = array();
363-
// while($row= $result->fetch_row()){
364-
// $ids[] = $row[0];
365-
// }
366-
//
367-
// foreach($ids as $idSP){
368-
// $num = rand(777, 33333);
369-
// $sql = "update sanpham set SoLanXem=$num where idSP=$idSP";
370-
// $this->db->query($sql);
371-
// }
372-
// }
373-
374-
// public function ngay(){
375-
// $sql = "select idSP from sanpham";
376-
// $result = $this->db->query($sql);
377-
//
378-
// $ids = array();
379-
// while($row= $result->fetch_row()){
380-
// $ids[] = $row[0];
381-
// }
382-
//
383-
// foreach($ids as $idSP){
384-
// $ngay = rand(1388530800, 1464732000);
385-
// $ngaycapnhat = date('Y-m-d', $ngay);
386-
// $sql = "update sanpham set NgayCapNhat='$ngaycapnhat' where idSP=$idSP";
387-
// $this->db->query($sql);
388-
// }
389-
// }
390-
391347
}

css/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ hr{margin: 10px 0;}
66
.nav-brand:hover{text-decoration: none; color: black;}
77
.header button{margin-top: 0;}
88
.active-cat{font-weight: bold;}
9-
109
.menuloai> li a{padding: 0px;}
1110

1211
#user-area{border-bottom: 1px solid #ddd; padding:5px; font-size: 15px;}

index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
<div class="row">
4747
<div class="col-md-12">
4848
<?php
49-
if(isset($_GET['action']) && $_GET['action']=='xemdonhang') require_once("donhang_chitiet.php");
49+
if(isset($_GET['timkiem'])) require_once("sanpham_timkiem.php");
50+
elseif(isset($_GET['action']) && $_GET['action']=='xemdonhang') require_once("donhang_chitiet.php");
5051
elseif(isset($_GET['action']) && $_GET['action'] =='thanhcong') require_once("dathangthanhcong.php");
5152
elseif(isset($_GET['action']) && $_GET['action'] =='thongtinnhanhang') require_once("thongtinnhanhang.php");
5253
elseif(isset($_GET['idSP'])) require_once("sanpham_chitiet.php");

sanpham_chitiet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<?php
2727
if($sp->laythuoctinhsp($_GET['idSP']) == '') echo "Đang cập nhật";
2828
echo $sp->laythuoctinhsp($_GET['idSP']);
29-
if($sanpham['baiviet'] != null) echo "<ul><li><a class='text-muted' href='#'>Xem thêm bài đánh giá</a></li></ul>";
29+
if($sanpham['baiviet'] != null) echo "<ul><li><a class='text-muted text-primary' href='#'>Xem thêm bài đánh giá</a></li></ul>";
3030
?>
3131
</div>
3232
</div>

sanpham_chungloai.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
<li>
2727
<form class="navbar-form navbar-left pull">
2828
<div class="input-group">
29-
<input type="text" class="form-control" placeholder="Search for...">
29+
<form method="get" action="index.php">
30+
<input type="text" class="form-control" name="timkiem" value="<?php if(isset($_GET['timkiem'])) echo $_GET['timkiem'];?>" placeholder="Tìm nhanh sản phẩm...">
3031
<span class="input-group-btn">
31-
<button class="btn btn-default" type="submit">Go!</button>
32+
<button class="btn btn-default" type="submit">Tìm!</button>
3233
</span>
34+
</form>
3335
</div>
3436
</form>
3537
</li>

sanpham_timkiem.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
$listsp = $sp->timkiemsanpham($_GET['timkiem'], $totalrows, $current_page, $per_page);
3+
$list_id_spmoi = $sp->layidspmoi($idCL, 10);
4+
?>
5+
<div class="list-sp panel panel-default">
6+
<div class="panel-heading">
7+
<h3 class="panel-title">Có <b><?php echo $totalrows;?></b> sản phẩm phù hợp với từ khóa <b>&quot;<?php echo $_GET['timkiem'];?>&quot;</b></h3>
8+
</div>
9+
<div class="panel-body">
10+
<div class="row">
11+
<?php
12+
if(count($listsp) == 0) echo "<h4>Đang cập nhật...!</h4>";
13+
else foreach($listsp as $sanpham)
14+
{
15+
?>
16+
<a href="index.php?chungloai=<?php echo $sanpham['idCL'];?>&loaisp=<?php echo $sanpham['idLoai'];?>&idSP=<?php echo $sanpham['idSP'];?>">
17+
<div class="tomtatsp col-md-2 col-sm-3 thumbnail">
18+
<center>
19+
<?php if(in_array($sanpham['idSP'], $list_id_spmoi)){?><span class="spmoi">Mới</span><?php }?>
20+
<span class="luotmua"><?php echo $sanpham['SoLanMua'] ?> lượt mua</span>
21+
<img class="tomtatsp-hinh img-responsive" src="upload/sanpham/hinhchinh/<?php echo $sanpham['urlHinh']; ?>" />
22+
<p><strong><?php echo $sanpham['TenSP'];?></strong></p>
23+
<p class="text-danger"><strong><?php echo number_format($sanpham['Gia'],0,',','.');?></strong><small>đ</small></p>
24+
</center>
25+
</div>
26+
</a>
27+
<?php
28+
}
29+
?>
30+
</div>
31+
</div>
32+
<div class="panel-footer">
33+
<?php
34+
$url = "http://localhost/banhang/index.php?timkiem={$_GET['timkiem']}";
35+
echo $sp->thanhphantrang($url, $totalrows, $current_page, $per_page, $pages_per_group);
36+
?>
37+
</div>
38+
</div>

0 commit comments

Comments
 (0)