-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstruments.php
More file actions
96 lines (70 loc) · 2.4 KB
/
instruments.php
File metadata and controls
96 lines (70 loc) · 2.4 KB
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
<?php
// Initialize empty movies array
$instruments = array();
// 1. Connect to my DB
$conn = mysqli_connect('localhost', 'root', '', 'music_shop');
// Did I connect successfully ?
if ($conn) {
$query = 'SELECT * FROM instruments';
// 2. Prepare the query
if (isset($_POST['searchBox'])) {
$mySearch = $_POST['searchBox'];
$query = "SELECT * FROM instruments WHERE name LIKE '%$mySearch%'";
}
// 3. Executing the query (send the query to the DB)
$results = mysqli_query($conn, $query);
// 4. Fetch the results in a associative array
$instruments = mysqli_fetch_all($results, MYSQLI_ASSOC);
} else {
echo 'Pb with connection !';
}
// Close the connection (you can close anywhere in the file)
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>INSTRUMENTS PAGE</title>
</head>
<body>
<h2>INSTRUMENTS list</h2>
<h4>Search for an INSTRUMENT : </h4>
<form action="" method="post">
<input type="text" name="searchBox" placeholder="Start typing name">
<input type="submit" name="searchBtn" value="Search">
</form>
<?php foreach ($instruments as $instrument) : ?>
<hr>
<p>
<strong>Name :</strong>
<!-- Same thing as echo -->
<?= $instrument['name']; ?>
</p>
<p>
<strong> Brand name:</strong>
<?php echo $instrument['brand_name']; ?>
</p>
<p>
<strong> Price:</strong>
<?php echo $instrument['price']; ?>
</p>
<p>
<strong> Photo:</strong>
<img src="<?= $instrument['photo']; ?>" alt="" width="100px">
</p>
<p>
<strong> Type:</strong>
<?php echo $instrument['type']; ?>
</p>
<p>
<strong> Description:</strong>
<?php echo substr($instrument['description'],0,19).' ...'; ?>
</p>
<!-- Link to 'Instrument detail' page, URL needs the id of the movie -->
<a href="instrument.php?id=<?= $instrument['id']; ?>">Instrument page</a>
<?php endforeach; ?>
</body>
</html>