-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilterfunction2 (1).php
More file actions
139 lines (126 loc) · 4.96 KB
/
Copy pathfilterfunction2 (1).php
File metadata and controls
139 lines (126 loc) · 4.96 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
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
<?php
include("ini/classes.php");
//require_once(".\search\dbcontroller.php");
//$db_handle = new DBController();
$onderwerp = "";
$wat = "";
$why = "";
$how = "";
$niveau = "";
/*
Gebruik ~* ipv LIKE, omdat deze functie:
a. Veel sneller is,
b. Caseinsensitive zoekt, dus hoofdletters zijn niet belangrijk
Je ziet dat je het hele stuk php-case kan weglaten hiermee, wat de code lekker kort en overzichtelijk houdt.
Net als LIKE kan ~* alleen bij zoek op argumenten van het type text en bijvoorbeeld niet op integer, daarom convert ik de laatste (niveau) voor de zekerheid naar text. Dit heeft wel als bijwerking dat als je zoekt op niveau 1 je ook niveau 10,11,12,etc tergu krijgt, omdat daar ook een 1 in zit. Soms is dat juist handig, soms juist niet. Dan moet je hem anders schrijven "AND niveau = COALESCE(".$niveau.",niveau)"
*/
//if(!empty($_POST["search"])) {
if(isset($_POST['Search'])
//er moet wel ergens op gezocht worden....
and !(empty($_POST["onderwerp"]) and empty($_POST["wat"]) and empty($_POST["why"]) and empty($_POST["how"]) and empty($_POST['niveau']))) {
$onderwerp = $_POST["onderwerp"];
$wat = $_POST["wat"];
$why = $_POST["why"];
$how = $_POST["how"];
if (! empty($_POST['niveau'])) {
$selectedOption="";
foreach ($_POST['niveau'] as $niveau) {
$selectedOption = $selectedOption . $niveau ;
if ( next( $_POST['niveau'] ) ) {
$selectedOption = $selectedOption . "|";
}
}
$niveau =$selectedOption;
} else {$niveau = "";}
$query = "SELECT * FROM sch_map.kenniskaart
WHERE onderwerp ~* '".$onderwerp."'
AND wat ~* '".$wat."'
AND why ~* '".$why."'
AND how ~* '".$how."'
AND niveau ~* '".$niveau."'
ORDER BY kenniskaart_id desc";
//echo $query;
// $result = $db_handle->runQuery($query);
$result=Connection::get()->connect()->query($query)->fetchAll(PDO::FETCH_ASSOC);
}
// ter voorbereiding van de opbouw van de combobox..
$comboquery = "SELECT lower(niveau) niveau FROM sch_map.kenniskaart group by niveau order by 1";
$comboresult=Connection::get()->connect()->query($comboquery)->fetchAll(PDO::FETCH_ASSOC);
if (! empty($comboresult)) {
foreach ($comboresult as $k => $v) {
echo '<option value="' . $comboresult[$k]['niveau'] . '">' . $comboresult[$k]['niveau'] . '</option>';
}
}
$htmlcode ='
<html>
<head>
<title>Zoeken</title>
<link href="style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<h2>PHP CRUD with Search and Pagination</h2>
<div id="toys-grid">
<form name="frmSearch" method="post" action="filterfunction.php">
<div class="search-box">
<p>
<input type="text" id="onderwerp" placeholder="onderwerp" name="onderwerp" class="demoInputBox" value="<?php echo $onderwerp; ?>"/>
<input type="text" id="wat" placeholder="wat" name="wat" class="demoInputBox" value="<?php echo $wat; ?>"/>
<input type="text" id="why" placeholder="why" name="why" class="demoInputBox" value="<?php echo $why; ?>"/>
<input type="text" id="how" placeholder="how" name="how" class="demoInputBox" value="<?php echo $how; ?>"/>
<select id="Place" id="niveau" name="niveau[]" multiple="multiple" SIZE="5">
</p>
</div>
'
?>
<?php
//echo display_sql_table($query,400);
?>
</select><br> <br>
<input type="submit" name="Search" id="Search" value="Search">
<input type="reset" class="btnSearch" value="Reset" onclick="window.location='filterfunction2.php'">
<table cellpadding="10" cellspacing="1">
<thead>
<tr>
<th><strong>Onderwerp</strong></th>
<th><strong>Rol</strong></th>
<th><strong>Competentie</strong></th>
<th><strong>Wat</strong></th>
<th><strong>Why</strong></th>
<th><strong>How</strong></th>
<th><strong>Plaatje</strong></th>
<th><strong>Bronnen</strong></th>
<th><strong>Niveau</strong></th>
<th><strong>Studieduur</strong></th>
<th><strong>Rating</strong></th>
</tr>
</thead>
<tbody>
<?php
if (! empty($result)) {
foreach ($result as $k => $v) {
if(is_numeric($k)) {
?>
<tr>
<td><?php echo $result[$k]["onderwerp"]; ?></td>
<td><?php echo $result[$k]["rol"]; ?></td>
<td><?php echo $result[$k]["competentie"]; ?></td>
<td><?php echo $result[$k]["wat"]; ?></td>
<td><?php echo $result[$k]["why"]; ?></td>
<td><?php echo $result[$k]["how"]; ?></td>
<td><img src='<?php echo $result[$k]["plaatje"]; ?>' ></td>
<td><?php echo $result[$k]["bronnen"]; ?></td>
<td><?php echo $result[$k]["niveau"]; ?></td>
<td><?php echo $result[$k]["studieduur"]; ?></td>
<td><?php echo $result[$k]["rating"]; ?></td>
</tr>
<?php
}
}
}
?>
<tbody>
</table>
</form>
</div>
</body>
</html>