-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch2.php
More file actions
162 lines (150 loc) · 5.87 KB
/
search2.php
File metadata and controls
162 lines (150 loc) · 5.87 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script src="sorttable.js" charset="utf-8"></script>
<title>PHP/PostgreSQL-test</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<script type="application/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
function search()
{
window.location = 'result.php';
}
</script>
<script>
// create the XMLHttpRequest object, according browser
function get_XmlHttp() {
// create the variable that will contain the instance of the XMLHttpRequest object (initially with null value)
var xmlHttp = null;
if(window.XMLHttpRequest) { // for Forefox, IE7+, Opera, Safari, ...
xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject) { // for Internet Explorer 5 or 6
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
// sends data to a php file, via POST, and displays the received answer
function ajaxrequest() {
var request = get_XmlHttp(); // call the function for the XMLHttpRequest instance
var rooms1 = document.getElementById('minRooms');
var rooms2 = document.getElementById('maxRooms');
var location = document.getElementById('location');
var object = document.getElementById('object');
// create pairs index=value with data that must be sent to server
var the_data = 'minArea='+document.getElementById('minArea').value+
'&maxArea='+document.getElementById('maxArea').value+
'&minRooms='+rooms1.options[rooms1.selectedIndex].value+
'&maxRooms='+rooms2.options[rooms2.selectedIndex].value+
'&minPrice='+document.getElementById('minPrice').value+
'&maxPrice='+document.getElementById('maxPrice').value+
'&minFee='+document.getElementById('minFee').value+
'&maxFee='+document.getElementById('maxFee').value+
'&location='+location.options[location.selectedIndex].value+
'&object='+object.options[object.selectedIndex].value+
'&orderBy=pris';
request.open("POST", "result2.php", true); // set the request
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// adds a header to tell the PHP script to recognize the data as is sent via POST
request.send(the_data); // calls the send() method with datas as parameter
// Check request status
// If the response is received completely, will be transferred to the HTML tag with
request.onreadystatechange = function() {
if (request.readyState == 4) {
document.getElementById("txtHint").innerHTML = request.responseText;
}
}
}
</script>
</head>
<body onload="ajaxrequest()">
<?php
//phpinfo();
$link = pg_connect("host=psql-vt2013 dbname=mathlin user=mathlin password=K5YKOU4tof");
$result = pg_exec($link, "select * from bostader");
$numrows = pg_numrows($result);
?>
<form>
Area, Min:
<input class="FormElement" id="minArea" type="text" size="3" maxlength="3" value="" onkeypress="return isNumberKey(event)" onchange="ajaxrequest()">
Max:
<input class="FormElement" id="maxArea" type="text" size="3" maxlength="3" value="" onkeypress="return isNumberKey(event)" onchange="ajaxrequest()">
<br />
Antal rum, Min:
<select id="minRooms" onchange="ajaxrequest()">
<?php
$roomResult = pg_query("SELECT DISTINCT rum FROM bostader ORDER BY rum");
$rows = pg_numrows($roomResult);
for($ri = 0; $ri < $rows; $ri++) {
$row = pg_fetch_array($roomResult, $ri);
echo "<option value='", $row["rum"], "'>", $row["rum"], "</option>";
}
?>
</select>
Max:
<select id="maxRooms" onchange="ajaxrequest()">
<?php
$roomResult = pg_query("SELECT DISTINCT rum FROM bostader ORDER BY rum");
$rows = pg_numrows($roomResult);
for($ri = 0; $ri < $rows; $ri++) {
$row = pg_fetch_array($roomResult, $ri);
if($ri + 1 == $rows) {
echo "<option selected value='", $row["rum"], "'>", $row["rum"], "</option>";
} else {
echo "<option value='", $row["rum"], "'>", $row["rum"], "</option>";
}
}
?>
</select>
<br />
Pris, Min:
<input class="FormElement" id="minPrice" type="text" size="9" maxlength="9" value="" onkeypress="return isNumberKey(event)" onchange="ajaxrequest()">
Max:
<input class="FormElement" id="maxPrice" type="text" size="9" maxlength="9" value="" onkeypress="return isNumberKey(event)" onchange="ajaxrequest()">
<br />
Avgift, Min:
<input class="FormElement" id="minFee" type="text" size="5" maxlength="5" value="" onkeypress="return isNumberKey(event)" onchange="ajaxrequest()">
Max:
<input class="FormElement" id="maxFee" type="text" size="5" maxlength="5" value="" onkeypress="return isNumberKey(event)" onchange="ajaxrequest()">
<br />
Län:
<select id="location" onchange="ajaxrequest()">
<option value='Samtliga'>Samtliga</option>
<?php
$lanResult = pg_query("SELECT DISTINCT lan FROM bostader ORDER BY lan");
$rows = pg_numrows($lanResult);
for($ri = 0; $ri < $rows; $ri++) {
$row = pg_fetch_array($lanResult, $ri);
echo "<option value='", $row["lan"], "'>", $row["lan"], "</option>";
}
?>
</select>
<br />
Boendetyp:
<select id="object" onchange="ajaxrequest()">
<option value='Samtliga'>Samtliga</option>
<?php
$objResult = pg_query("SELECT DISTINCT objekttyp FROM bostader ORDER BY objekttyp");
$rows = pg_numrows($objResult);
for($ri = 0; $ri < $rows; $ri++) {
$row = pg_fetch_array($objResult, $ri);
echo "<option value='", $row["objekttyp"], "'>", $row["objekttyp"], "</option>";
}
?>
</select>
<br />
<br />
<br />
<br />
</form>
<br>
<div id="txtHint"><b>Table will go here!</b></div>
</body>
</html>