-
Notifications
You must be signed in to change notification settings - Fork 0
/
order-backend-search.php
66 lines (62 loc) · 2.46 KB
/
order-backend-search.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
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
try{
$pdo = new PDO("mysql:host=localhost;dbname=fnf", "root", "");
// Set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
die("ERROR: Could not connect. " . $e->getMessage());
}
// Attempt search query execution
try{
if(isset($_REQUEST["term"])){
// create prepared statement
$sql = "SELECT `o`.*, `c`.`first_name`, `c`.`last_name`, `c`.`email`, `c`.`phone`
FROM `orders` AS `o`
LEFT JOIN `customers` AS `c` ON `c`.`id` = `o`.`customer_id`
WHERE `o`.`id` LIKE :term
OR `c`.`first_name` LIKE :term
OR `c`.`last_name` LIKE :term
OR `c`.`phone` LIKE :term
OR `c`.`email` LIKE :term";
$stmt = $pdo->prepare($sql);
$term = $_REQUEST["term"] . '%';
// bind parameters to statement
$stmt->bindParam(":term", $term);
// execute the prepared statement
$stmt->execute();
if($stmt->rowCount() > 0){
while($order = $stmt->fetch()){
$oid = $order['id'];
$status = $order['status'];
echo '<p>';
if ( $status = "pending"){
echo '<img src="images/packed.png" width="25px" height="25px" alt="Packed" title="Packed"/>';
} elseif( $status = "delivery"){
echo '<img style="background: #00FF21;" src="images/truck.png" width="50px" height="50px" alt="Delivery" title="Delivery"/>';
} elseif( $status = "completed"){
echo '<img style="background: #00FF21;" src="images/completed.png" width="50px" height="50px" alt="Completed" title="Completed"/>';
} elseif( $status = "canceled"){
echo '<img style="background: #00FF21;" src="images/cancelled.png" width="50px" height="50px" alt="Cancelled" title="Cancelled"/>';
} else {
echo '<img style="background: #00FF21;" src="images/error.png" width="50px" height="50px" alt="Error" title="Error"/>';
}
?>
<a href="orderview.php?oid=<?php echo $order['id']; ?>" style="text-decoration: none; color:black;"><?php echo $order['id'] . ' ' . $order['first_name'] . ' ' . $order['last_name'] . ' ' . $order['phone'] ?>
</a>
</p>
<?php
}
} else {
echo "<p>No matches found</p>";
}
}
} catch(PDOException $e){
die("ERROR: Could not able to execute $sql. " . $e->getMessage());
}
// Close statement
unset($stmt);
// Close connection
unset($pdo);
?>