Created
October 8, 2017 09:45
-
-
Save minhphong306/985ae78923985ee680d4cd1e3498ca4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$host = 'localhost'; | |
$username = 'root'; | |
$passwd = 'PhongDP25#*'; | |
$dbname = 'online_shopping'; | |
$conn = new mysqli($host, $username, $passwd, $dbname); | |
$query = "SELECT * FROM category order by name"; | |
$data = $conn->query($query); | |
$newline = '<br/>'; | |
echo "<form method='GET'>"; | |
echo "<select id='category_list' name='cat_id' onchange='this.form.submit()'>"; | |
echo "<option>Vui long chon category</option>"; | |
while ($row = $data->fetch_assoc()) { | |
$id = $row['Id']; | |
$name = $row['Name']; | |
echo "<option value='$id'>"; | |
echo "$name"; | |
echo "</option>"; | |
} | |
echo "</select>"; | |
echo "</form>"; | |
if (isset($_GET['cat_id'])) { | |
$cat_id = $_GET['cat_id']; | |
$query = "SELECT p.id, p.Name, c.Name as Cat_name, p.Description, p.Price, p.Is_active | |
from product p join category c | |
on p.Cat_id = c.Id | |
where p.cat_id = $cat_id | |
order by p.Name"; | |
$data = $conn->query($query); | |
echo "<table> | |
<col style=\"width:20%\"> | |
<col style=\"width:20%\"> | |
<col style=\"width:20%\"> | |
<col style=\"width:20%\"> | |
<col style=\"width:20%\"> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th>Category</th> | |
<th>Description</th> | |
<th>Price</th> | |
<th>Active</th> | |
</tr> | |
</thead> | |
<tbody>"; | |
while ($row = $data->fetch_assoc()) { | |
$name = $row['Name']; | |
$cname = $row['Cat_name']; | |
$des = $row['Description']; | |
$price = $row['Price']; | |
$is_active = $row['Is_active']; | |
echo "<tr><td>$name</td> | |
<td>$cname</td> | |
<td>$des</td> | |
<td>$price</td> | |
<td>$is_active</td></tr>"; | |
} | |
echo "</tbody></table>"; | |
} | |
$conn->close(); | |
?> | |
<style> | |
table, thead, tbody, tr, th, td{ | |
border: 1px solid black; | |
} | |
</style> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment