-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall.php
178 lines (158 loc) · 6.74 KB
/
all.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
include 'dbconfig.php';
include 'nav.php';
?>
<style>
.container{
display: flex;
flex-wrap: wrap;
gap: 2em;
width: 100%;
padding: 25px;
}
*{
/* border: 1px solid red; */
margin: 0px;
padding: 0px;
}
.cards{
/* display: flex; */
/* justify-content: center; */
border-radius: 10px;
overflow: hidden;
width: auto;
height: 20rem;
flex-direction: column;
text-align: center;
border: 1px solid;
padding: 5px;
}
.cards img{
width: auto;
max-width: 14rem;
height: 16rem;
border-radius: 10px;
border: none;
}
</style>
<div class="section">
<?php
if(!empty($_GET['type'])){
$type = $_GET['type'];
if($type == "products"){
$sql = mysqli_query($conn,"SELECT * FROM product");
if($sql){
while($result = mysqli_fetch_assoc($sql)){
$id=$result['pid'];
$check = mysqli_query($conn,"SELECT * FROM sale WHERE pid = $id");
?>
<div class="view">
<a href="view_product.php?id=<?=$id?>"><img src="images/<?=$result['img_url']?>" width="200px" height="200px" alt=""></a>
<a href="view_product.php?id=<?=$id?>"><?php echo $result['product']; ?></a>
<?php
if(mysqli_num_rows($check) == 0){?>
<a href="view_product.php?id=<?=$id?>"><?=$result['price']?></a>
<?php }else{
$sale = mysqli_fetch_assoc($check); ?>
<a href="view_product.php?id=<?=$id?>"><?=$sale['sale_amt']?></a>
<?php }
?>
<form action="buy.php?id=<?=$id?>&type=product" method="post">
<input type="submit" value="Buy Now" name="buy" class="buy-btn">
<input type="submit" value="Add To Cart" name="cart" class="cart-btn">
</form>
</div>
<?php }}
}
elseif($type == "brands"){
$sql = mysqli_query($conn, "SELECT DISTINCT brand from product");
$result = "";
while($result = mysqli_fetch_array($sql)){
// echo $result['brand'];
echo
'
<div class="cards">
<a href="all.php?type='.$result['brand'].'"><img src="images/'.$result['brand'].'.png" alt="'.$result['brand'].'"></a><br>
<h2>'.$result['brand'].'</h2>
</div>
';
}
}
else{
$stype = strtolower($type);
$query = mysqli_query($conn,"SELECT * FROM product WHERE p_type = '$type' OR p_type = '$stype'" );
if(mysqli_num_rows($query) == 0){
$sql = mysqli_query($conn,"SELECT * FROM product WHERE brand = '$type'");
if($sql){
while($result = mysqli_fetch_assoc($sql)){ $id=$result['pid'];
$check = mysqli_query($conn,"SELECT * FROM sale WHERE pid = $id");?>
<div class="view">
<a href="view_product.php?id=<?=$id?>"><img src="images/<?=$result['img_url']?>" width="200px" height="200px" alt=""></a>
<a href="view_product.php?id=<?=$id?>"><?php echo $result['product']; ?></a>
<?php
if(mysqli_num_rows($check) == 0){?>
<a href="view_product.php?id=<?=$id?>"><?=$result['price']?></a>
<?php }else{
$sale = mysqli_fetch_assoc($check); ?>
<a href="view_product.php?id=<?=$id?>"><?=$sale['sale_amt']?></a>
<?php }
?>
<form action="buy.php?id=<?=$id?>&type=product" method="post">
<input type="submit" value="Buy Now" name="buy" class="buy-btn">
<input type="submit" value="Add To Cart" name="cart" class="cart-btn">
</form>
</div>
<?php }}}
else{
$query = mysqli_query($conn,"SELECT * FROM product WHERE p_type = '$type' OR p_type = '$stype'" );
while($result = mysqli_fetch_assoc($query)){
$id=$result['pid'];
$check = mysqli_query($conn,"SELECT * FROM sale WHERE pid = $id");?>
<div class="view">
<a href="view_product.php?id=<?=$id?>"><img src="images/<?=$result['img_url']?>" width="200px" height="200px" alt=""></a>
<a href="view_product.php?id=<?=$id?>"><?php echo $result['product']; ?></a>
<?php
if(mysqli_num_rows($check) == 0){?>
<a href="view_product.php?id=<?=$id?>"><?=$result['price']?></a>
<?php }else{
$sale = mysqli_fetch_assoc($check); ?>
<a href="view_product.php?id=<?=$id?>"><?=$sale['sale_amt']?></a>
<?php }
?>
<form action="buy.php?id=<?=$id?>&type=product" method="post">
<input type="submit" value="Buy Now" name="buy" class="buy-btn">
<input type="submit" value="Add To Cart" name="cart" class="cart-btn">
</form>
</div>
<?php }
}
}
}//not empty type end
else{
$sql = mysqli_query($conn,"SELECT * FROM product");
if($sql){
while($result = mysqli_fetch_assoc($sql)){ $id=$result['pid'];
$check = mysqli_query($conn,"SELECT * FROM sale WHERE pid = $id");?>
<div class="view">
<a href="view_product.php?id=<?=$id?>"><img src="images/<?=$result['img_url']?>" width="200px" height="200px" alt=""></a>
<a href="view_product.php?id=<?=$id?>"><?php echo $result['product']; ?></a>
<?php
if(mysqli_num_rows($check) == 0){?>
<a href="view_product.php?id=<?=$id?>"><?=$result['price']?></a>
<?php }else{
$sale = mysqli_fetch_assoc($check); ?>
<a href="view_product.php?id=<?=$id?>"><?=$sale['sale_amt']?></a>
<?php }
?>
<form action="buy.php?id=<?=$id?>&type=product" method="post">
<input type="submit" value="Buy Now" name="buy" class="buy-btn">
<input type="submit" value="Add To Cart" name="cart" class="cart-btn">
</form>
</div>
<?php }}
}
?>
</div>
<?php include 'footer.php'; ?>
</body>
</html>