-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterials_list.php
More file actions
23 lines (21 loc) · 766 Bytes
/
Copy pathmaterials_list.php
File metadata and controls
23 lines (21 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
require_once 'includes/auth.php';
require_login();
require_once 'includes/db.php';
$where = [];
$params = [];
if (isset($_GET['search']) && $_GET['search'] !== '') {
$where[] = '(product_code LIKE ? OR product_name LIKE ? OR supplier LIKE ?)';
$params[] = "%{$_GET['search']}%";
$params[] = "%{$_GET['search']}%";
$params[] = "%{$_GET['search']}%";
}
if (isset($_GET['is_active']) && ($_GET['is_active'] == "0" || $_GET['is_active'] == "1")) {
$where[] = 'is_active = ?';
$params[] = $_GET['is_active'];
}
$sql = "SELECT * FROM materials" . ($where ? ' WHERE '.implode(' AND ', $where) : '');
$sql .= " ORDER BY product_name";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));