Lijst met adres overzicht sorteren op alfabet bij stad
Ik ben bezig een site voor een vriend aan te passen die op zijn site kantoorruimte aanbiedt. Het probleem is het volgende:
Wanneer je op de naam van een stad klikt krijg een google maps kaartje van die stad te zien met daarin de markers van de locaties (kantoorruimte)en daaronder een lijst met de adressen, uit een database. deze lijst is echter niet gesorteerd, dit maakt het vinden van een adres lastig. nu vraag ik me af hoe ik het best de lijst kan sorteren op alfabet.
Hieronder het stuk code wat de lijst samenstelt:
Code (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
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
<?php
echo "<p> </p>
<table cellpadding='0' cellspacing='0' border='0' class='listing'>
<thead>
<tr>
<th class='info'>Info</th>
<th class='plaats'>Plaats</th>
<th class='adres'>Adres</th>
<th class='bestemming'>Bestemming</th>
<th class='oppervlakte'>Oppervlakte</th>
<th class='soort'>Soort</th>
<th class='prijs'>Prijs</th>
<th class='foto'>Foto</th>
</tr>
</thead>
<tbody>";
$pc = count($results);
for($p=0; $p<$pc; $p++){
$oId = $results[$p];
$address = getObjectField($oId, "adres");
$city = getObjectField($oId, "plaats");
if($city != -1){
$city = getObjectField($city, "naam");
}
$areaMin = getObjectField($oId, "oppervlakte minimaal");
$areaMax = getObjectField($oId, "oppervlakte maximaal");
$area = $areaMin ." m²". (($areaMax != "")? " - ". $areaMax ." m²" : "" );
$price = getObjectField($oId, "prijs");
$url = FriendlyURLs::getObjectURL($city, $oId);
echo "<tr>";
echo "<td><a href='". $url ."' title='". htmlentities( $address ) ."'><img src='". $_BASEURL_SITE ."images/marker.gif' /></a></td>";
echo "<td>". $city ."</td>";
echo "<td><a href='". $url ."'>". $address ."</a></td>";
echo "<td>Kantoorruimte</td>";
echo "<td>". $area ."</td>";
echo "<td>huren</td>";
echo "<td>". $price ."</td><td><a href='". $url ."' title='". htmlentities( $address ) ."'>";
$fotoId = $this->util->getFirstThumbnail($oId);
if($fotoId != -1){
$this->util->outputListingThumbnail($fotoId);
}
echo "</a></td></tr>";
}
echo "</tbody></table>";
?>
echo "<p> </p>
<table cellpadding='0' cellspacing='0' border='0' class='listing'>
<thead>
<tr>
<th class='info'>Info</th>
<th class='plaats'>Plaats</th>
<th class='adres'>Adres</th>
<th class='bestemming'>Bestemming</th>
<th class='oppervlakte'>Oppervlakte</th>
<th class='soort'>Soort</th>
<th class='prijs'>Prijs</th>
<th class='foto'>Foto</th>
</tr>
</thead>
<tbody>";
$pc = count($results);
for($p=0; $p<$pc; $p++){
$oId = $results[$p];
$address = getObjectField($oId, "adres");
$city = getObjectField($oId, "plaats");
if($city != -1){
$city = getObjectField($city, "naam");
}
$areaMin = getObjectField($oId, "oppervlakte minimaal");
$areaMax = getObjectField($oId, "oppervlakte maximaal");
$area = $areaMin ." m²". (($areaMax != "")? " - ". $areaMax ." m²" : "" );
$price = getObjectField($oId, "prijs");
$url = FriendlyURLs::getObjectURL($city, $oId);
echo "<tr>";
echo "<td><a href='". $url ."' title='". htmlentities( $address ) ."'><img src='". $_BASEURL_SITE ."images/marker.gif' /></a></td>";
echo "<td>". $city ."</td>";
echo "<td><a href='". $url ."'>". $address ."</a></td>";
echo "<td>Kantoorruimte</td>";
echo "<td>". $area ."</td>";
echo "<td>huren</td>";
echo "<td>". $price ."</td><td><a href='". $url ."' title='". htmlentities( $address ) ."'>";
$fotoId = $this->util->getFirstThumbnail($oId);
if($fotoId != -1){
$this->util->outputListingThumbnail($fotoId);
}
echo "</a></td></tr>";
}
echo "</tbody></table>";
?>
Het gaat om het sorteren van "address" in regel 39.
ik heb al "sort($address)" geprobeerd, maar dan krijg ik deze foutmelding:
Warning: sort() expects parameter 1 to be array, string given in C:\***.nl\scripts\class.content.php on line 590
(deze foutmelding krijg ik dan zovaak als er adressen zijn)
elders in de site wordt een overzicht van steden op deze manier gesorteerd:
Code (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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
private function outputCities(){
echo "<h1>Steden</h1>";
$cities = getObjectIdByTemplate("plaats");
$cl = count($cities);
for($c=0; $c<$cl; $c++){
$cities[$c] = getObjectField($cities[$c], "naam");
}
sort($cities);
$colC = ceil($cl / 4);
echo "<ol class=\"linklist\">";
for($c=0; $c<$cl; $c++){
if($c>0 and $c % $colC == 0){
echo "</ol><ol class=\"linklist\">";
}
echo "<li><a href=\"". FriendlyURLs::getCityURL($cities[$c]) ."\">". $cities[$c] ."</a></li>";
}
echo "</ol><div class=\"clear\"></div>";
}
?>
private function outputCities(){
echo "<h1>Steden</h1>";
$cities = getObjectIdByTemplate("plaats");
$cl = count($cities);
for($c=0; $c<$cl; $c++){
$cities[$c] = getObjectField($cities[$c], "naam");
}
sort($cities);
$colC = ceil($cl / 4);
echo "<ol class=\"linklist\">";
for($c=0; $c<$cl; $c++){
if($c>0 and $c % $colC == 0){
echo "</ol><ol class=\"linklist\">";
}
echo "<li><a href=\"". FriendlyURLs::getCityURL($cities[$c]) ."\">". $cities[$c] ."</a></li>";
}
echo "</ol><div class=\"clear\"></div>";
}
?>
het lukt mij echter niet dit bij het overzicht van de adressen voor elkaar te krijgen.
Kan iemand mij hiermee helpen?
Alvast dank!
Gewijzigd op 17/05/2010 21:38:00 door Peps from Yesterday
Wat ;lukt er niet?
Gewijzigd op 17/05/2010 21:40:30 door Peps from Yesterday
Sort()
Komt het uit een database?
SELECT * FROM adressen ORDER BY adres DESC
als ik sort() gebruik krijg ik dus een foutmelding.
Peps, je zit net verkeerd. Je moet niet daar (op regel 39) sorteren, maar daarvoor waar je de data ophaalt ($results) ;-)
In je scriptvoorbeeld is niet te zien hoe de info wordt opgehaald. Laat even de SELECT query zien waar dat gebeurt.
de url is steeds ../3201/amsterdam/herengracht...
door te sorteren op result werd (jammer genoeg) gesorteerd op het getal : /3201/ enz..
Peps, je moet $result laten zien, die moet namelijk worden veranderd. De query gaat het dus om ;-)
@ chris, wat bedoel je met de "$results" laten zien? en waar moet ik die in veranderen?
Je hebt in je script $results. Waar wordt die gedefinieerd?
Code (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
<?php
/** Google map */
$search = new Search($this->navigation);
$results = $search->getResults();
if(count($results) > 0){
echo "<h2>Aangeboden kantoorruimte in ". $this->navigation->parsedPlaats() .":</h2>";
?>
<div class='mapholder city'>
<div id='bigmap'></div>
</div>
<script type="text/javascript">
//<![CDATA[
$(function(){
if(GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("bigmap"));
var geo = new GClientGeocoder();
var icon = new GIcon();
icon.image = "<?php echo $_BASEURL_SITE ?>images/marker.gif";
icon.iconSize = new GSize(25,25);
icon.transparent = "<?php echo $_BASEURL_SITE ?>images/marker_ie.png";
icon.iconAnchor = new GPoint(12,13);
icon.infoWindowAnchor = new GPoint(25,0);
/** zoom city */
geo.getLatLng(
"<?php echo $this->navigation->parsedPlaats() ?>, Nederland",
function(point) {
if (!point) {
} else {
map.setCenter(point, 10);
}
}
);
<?php
$pc = count($results);
for($p=0; $p<$pc; $p++){
$oId = $results[$p];
$city = getObjectField($oId, "plaats");
$postal = getObjectField($oId, "postcode");
$address = getObjectField($oId, "adres");
if($city != -1){
$city = getObjectField($city, "naam");
}
$url = FriendlyURLs::getObjectURL($city, $oId);
?>
geo.getLatLng(
"<?php echo $address .", ". $postal ?>, Nederland",
function(point) {
if (!point) {
} else {
var marker = new GMarker(point, {
icon: icon,
title: "<?php echo $address .", ". $city ?>"
});
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<div><a href="<?php echo $url ?>"><?php echo $address .", ". $city ?></a><br /><?php $this->util->outputFirstThumbnail($oId) ?></div>');
});
map.addOverlay(marker);
}
}
);
<?php
}
?>
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.disableScrollWheelZoom();
$(document).unload(function(){
GUnload();
});
}
});
//]]>
</script>
?>
/** Google map */
$search = new Search($this->navigation);
$results = $search->getResults();
if(count($results) > 0){
echo "<h2>Aangeboden kantoorruimte in ". $this->navigation->parsedPlaats() .":</h2>";
?>
<div class='mapholder city'>
<div id='bigmap'></div>
</div>
<script type="text/javascript">
//<![CDATA[
$(function(){
if(GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("bigmap"));
var geo = new GClientGeocoder();
var icon = new GIcon();
icon.image = "<?php echo $_BASEURL_SITE ?>images/marker.gif";
icon.iconSize = new GSize(25,25);
icon.transparent = "<?php echo $_BASEURL_SITE ?>images/marker_ie.png";
icon.iconAnchor = new GPoint(12,13);
icon.infoWindowAnchor = new GPoint(25,0);
/** zoom city */
geo.getLatLng(
"<?php echo $this->navigation->parsedPlaats() ?>, Nederland",
function(point) {
if (!point) {
} else {
map.setCenter(point, 10);
}
}
);
<?php
$pc = count($results);
for($p=0; $p<$pc; $p++){
$oId = $results[$p];
$city = getObjectField($oId, "plaats");
$postal = getObjectField($oId, "postcode");
$address = getObjectField($oId, "adres");
if($city != -1){
$city = getObjectField($city, "naam");
}
$url = FriendlyURLs::getObjectURL($city, $oId);
?>
geo.getLatLng(
"<?php echo $address .", ". $postal ?>, Nederland",
function(point) {
if (!point) {
} else {
var marker = new GMarker(point, {
icon: icon,
title: "<?php echo $address .", ". $city ?>"
});
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<div><a href="<?php echo $url ?>"><?php echo $address .", ". $city ?></a><br /><?php $this->util->outputFirstThumbnail($oId) ?></div>');
});
map.addOverlay(marker);
}
}
);
<?php
}
?>
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.disableScrollWheelZoom();
$(document).unload(function(){
GUnload();
});
}
});
//]]>
</script>
?>
Gewijzigd op 18/05/2010 00:03:55 door Peps from Yesterday
edit: Misschien heeft die class zelf wel een optie om je resultaten te sorteren. Zou je die class eens kunnen posten?
Gewijzigd op 17/05/2010 22:46:14 door Jelmer -
Code (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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php
/**
*
*/
require_once("scripts/class.util.php");
define("MAXOPP", "geen");
define("PAGESIZE", 6);
class Search{
var $navigation;/** instance of Navigation */
var $util;
var $criteria;
//*** PHP 5
public function __construct($navigation){
//*** defaults
$this->navigation = $navigation;
$this->util = new Util();
$this->extractCriteria();
}
//*** PHP 4
public function Search($navigation){
$this->__construct($navigation);
}
private function extractCriteria(){
$this->criteria = array(
"plaats"=> $this->navigation->plaats(),
"plaatsId"=>-1,
"provincie"=> $this->navigation->provincie(),
"provincieId"=>-1,
"min_opp"=>$this->navigation->getRequestVar("min_opp", "integer", 0),
"max_opp"=>$this->navigation->getRequestVar("max_opp", "string", "geen"),
"pagina"=>$this->navigation->getRequestVar("pagina", "integer", 1)
);
$ids = getObjectIdByTemplateFieldValue("plaats", "naam", $this->criteria["plaats"]);
if(count($ids) > 0){
$this->criteria["plaatsId"] = $ids[0];
}
$ids = getObjectIdByTemplateFieldValue("provincie", "naam", $this->criteria["provincie"]);
if(count($ids) > 0){
$this->criteria["provincieId"] = $ids[0];
}
}
public function getCriteria(){
return $this->criteria;
}
public function getLink($withPage = false){
$criteria = $this->getCriteria();
$url = "";
if($criteria["plaats"] != ""){
$url = FriendlyURLs::getCitySearchURL($criteria["plaats"]);
}else if($criteria["provincie"] != ""){
$url = FriendlyURLs::getProvinceSearchURL($criteria["provincie"]);
}
if($url != ""){
$url .= "?min_opp=". $criteria["min_opp"] ."&max_opp=". $criteria["max_opp"];
}
if($withPage){
$url .= ($this->criteria["pagina"] > 1)? '&pagina='. $this->criteria["pagina"] : '';
}
return $url;
}
public function getFeed(){
$criteria = $this->getCriteria();
$url = "";
if($criteria["plaats"] != ""){
$url = FriendlyURLs::getCityFeedURL($criteria["plaats"]);
}else if($criteria["provincie"] != ""){
$url = FriendlyURLs::getProvinceFeedURL($criteria["provincie"]);
}
if($url != ""){
$url .= "?min_opp=". $criteria["min_opp"] ."&max_opp=". $criteria["max_opp"];
}
return $url;
}
public function getDescription(){
return "*******.nl zoekresultaat: ". $this->getShortDescription();
}
public function getShortDescription(){
$criteria = $this->getCriteria();
$desc = "";
$extra = "";
if($criteria["max_opp"] != MAXOPP){
$extra = " met een oppervlakte tussen ". $criteria["min_opp"] ."m2 en ". $criteria["max_opp"] ."m2";
}else if($criteria["min_opp"] != 0){
$extra = " met een minimale oppervlakte van ". $criteria["min_opp"] ."m2";
}
if($criteria["plaats"] != ""){
if($criteria["plaatsId"] != -1){
$desc = "kantoorruimte in ". getObjectField($criteria["plaatsId"], "naam").
$extra;
}else{
$desc = "kantoorruimte in ". $criteria["plaats"].
$extra;
}
}else if($criteria["provincie"] != ""){
if($criteria["provincieId"] != -1){
$desc = "kantoorruimte in provincie ". getObjectField($criteria["provincieId"], "naam").
$extra;
}else{
$desc = "kantoorruimte in provincie ". $criteria["provincie"].
$extra;
}
}
return $desc;
}
/**
* All searchcriteria options are stored in fn_object_field_smalltext (for now)
*/
public function showResult(){
if($this->navigation->getPostVar("notify", "string", "") == ""){
$results = $this->getResults();
if(count($results) > 0){
$this->outputResults($results, $this->criteria["pagina"]);
$this->outputPager(count($results), $this->criteria["pagina"]);
}else{
$this->outputNotifyForm();
}
}else{
$this->outputNotifyForm();
}
}
public function getResults(){
$results = array();
$locationIds = array();
if($this->criteria["plaatsId"] != -1){
$locationIds[] = $this->criteria["plaatsId"];
}else if($this->criteria["provincieId"] != -1){
$locationIds = getObjectIdByTemplateFieldValue("plaats", "provincie", $this->criteria["provincieId"]);
}
if(count($locationIds) > 0){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE f.active".
" AND s.tfId = ". getTemplateFieldIdByName("ruimte", "plaats");
if(count($locationIds) > 1){
$sql .= " AND s.value IN (". implode($locationIds, ',') .")";
}else{
$sql .= " AND s.value = ". $locationIds[0];
}
$sql .= " ORDER BY f.creation_date DESC";
$res1 = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res1) > 0){
while($row=mysql_fetch_assoc($res1)){
$results[] = $row["oId"];
}
if($this->criteria["min_opp"] > 0){
$pre = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = ". getTemplateFieldIdByName("ruimte", "oppervlakte minimaal");
if($this->criteria["max_opp"] != MAXOPP && is_numeric($this->criteria["max_opp"])){
/*
get
res1 min gebouw tussen min opp en max opp
res2 max gebouw tussen min opp en max opp, exclude res1
res3 min gebouw < min
res4 max gebouw > max opp IN res4
add to total!
*/
//*** RANGE 1 starting or ending between MIN/MAX
/** first get a temporary result for the minimum area */
$pre .= " AND s.value BETWEEN ". $this->criteria["min_opp"] ." AND ". $this->criteria["max_opp"];
$sql = $pre ." AND f.oId IN (". implode($results, ',') .")".
" ORDER BY f.creation_date DESC";
$totalresults = array();
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
//now check maximum
if(count(array_diff($results, $totalresults)) > 0){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte maximaal")."'".
" AND s.value != ''".
" AND s.value BETWEEN ". $this->criteria["min_opp"] ." AND ". $this->criteria["max_opp"] .
" AND f.oId IN (". implode(array_diff($results, $totalresults), ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
}
//*** RANGE 2 start and end outside MIN/MAX
if(count(array_diff($results, $totalresults)) > 0){
$resOutside = array();
//*** MAX outside
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte maximaal")."'".
" AND s.value != ''".
" AND s.value > ". $this->criteria["max_opp"] .
" AND f.oId IN (". implode(array_diff($results, $totalresults), ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$resOutside[] = $row["oId"];
}
//*** MIN outside
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte minimaal")."'".
" AND s.value != ''".
" AND s.value < ". $this->criteria["min_opp"] .
" AND f.oId IN (". implode($resOutside, ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
}
}
$results = $totalresults;
}else{
$pre .= " AND s.value >= ". $this->criteria["min_opp"];
$sql = $pre ." AND f.oId IN (". implode($results, ',') .")".
" ORDER BY f.creation_date DESC";
$totalresults = array();
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
//now check maximum
if(count(array_diff($results, $totalresults)) > 0){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte maximaal")."'".
" AND (s.value >= ". $this->criteria["min_opp"]." AND s.value != '')".
" AND f.oId IN (". implode( array_diff($results, $totalresults) , ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
}
$results = $totalresults;
}
}else if($this->criteria["max_opp"] != MAXOPP && is_numeric($this->criteria["max_opp"])){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte minimaal")."'".
" AND s.value <= ". $this->criteria["max_opp"].
" AND f.oId IN (". implode($results, ',') .")".
" ORDER BY f.creation_date DESC";
$results = array();
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$results[] = $row["oId"];
}
}
}
}
}
return $results;
}
private function outputResults($results, $page){
$page = ($page > 0)? $page-1 : $page;
$results = array_slice($results, $page*PAGESIZE, PAGESIZE);
echo "<h1>Kantoorruimte huren ". $this->navigation->parsedPlaats() ."</h1>";
echo "<ol id=\"searchresult\">";
$pc = count($results);
for($p=0; $p<$pc; $p++){
$oId = $results[$p];
$city = getObjectField($oId, "plaats");
if($city != -1){
$city = getObjectField($city, "naam");
}
$url = FriendlyURLs::getObjectURL($city, $oId);
?>
<li>
<a href="<?php echo $url ?>" title="Meer informatie / prijsopgave"><div class="thumb"><div class="cover"></div><?php $this->util->outputFirstThumbnail($oId) ?></div></a>
<div class="info">
<h2><?php echo getObjectField($oId, "adres") .", ". getObjectField($oId, "postcode") ?><label><?php echo $city ?></label></h2>
<p>
<?php
$this->outputExcerpt($oId);
?>
</p>
<a href="<?php echo $url ?>">Meer informatie / prijsopgave</a>
</div>
<div class="clear"></div>
</li>
<?php
}
echo "</ol>";
}
private function outputPager($numresults, $page){
echo '<div id="pager">';
if($page > 1){
echo '<a href="'. $this->getLink() ."&pagina=". ($page - 1) .'" class="back"><Terug</a> ';
}
$pages = ceil($numresults / PAGESIZE);
if($pages > 1){
for($p=1; $p<=$pages; $p++){
if($p == $this->criteria["pagina"]){
echo "<strong>$p</strong>";
}else{
echo '<a href="'. $this->getLink() .'&pagina='. $p .'">'. $p .'</a> ';
}
if($p != $pages){
echo "| ";
}
}
}
if($page < $pages){
echo '<a href="'. $this->getLink() ."&pagina=". ($page + 1) .'" class="forward">Verder></a> ';
}
echo "</div>";
}
private function outputNotifyForm($showIntro = true){
require_once("class.form.php");
$notifyForm = new SearchRequestForm($this->navigation);
$parsed = false;
if($notifyForm->posted()){
$parsed = $notifyForm->parse($this);
}
if($parsed){
$notifyForm->finished();
}else{
$notifyForm->show($this);
}
}
private function outputExcerpt($oId){
$text = strip_tags(getObjectField($oId, "omschrijving"));
if(strlen($text) > 350){
echo substr($text, 0, 350)."...";
}else{
echo $text;
}
}
}
?>
/**
*
*/
require_once("scripts/class.util.php");
define("MAXOPP", "geen");
define("PAGESIZE", 6);
class Search{
var $navigation;/** instance of Navigation */
var $util;
var $criteria;
//*** PHP 5
public function __construct($navigation){
//*** defaults
$this->navigation = $navigation;
$this->util = new Util();
$this->extractCriteria();
}
//*** PHP 4
public function Search($navigation){
$this->__construct($navigation);
}
private function extractCriteria(){
$this->criteria = array(
"plaats"=> $this->navigation->plaats(),
"plaatsId"=>-1,
"provincie"=> $this->navigation->provincie(),
"provincieId"=>-1,
"min_opp"=>$this->navigation->getRequestVar("min_opp", "integer", 0),
"max_opp"=>$this->navigation->getRequestVar("max_opp", "string", "geen"),
"pagina"=>$this->navigation->getRequestVar("pagina", "integer", 1)
);
$ids = getObjectIdByTemplateFieldValue("plaats", "naam", $this->criteria["plaats"]);
if(count($ids) > 0){
$this->criteria["plaatsId"] = $ids[0];
}
$ids = getObjectIdByTemplateFieldValue("provincie", "naam", $this->criteria["provincie"]);
if(count($ids) > 0){
$this->criteria["provincieId"] = $ids[0];
}
}
public function getCriteria(){
return $this->criteria;
}
public function getLink($withPage = false){
$criteria = $this->getCriteria();
$url = "";
if($criteria["plaats"] != ""){
$url = FriendlyURLs::getCitySearchURL($criteria["plaats"]);
}else if($criteria["provincie"] != ""){
$url = FriendlyURLs::getProvinceSearchURL($criteria["provincie"]);
}
if($url != ""){
$url .= "?min_opp=". $criteria["min_opp"] ."&max_opp=". $criteria["max_opp"];
}
if($withPage){
$url .= ($this->criteria["pagina"] > 1)? '&pagina='. $this->criteria["pagina"] : '';
}
return $url;
}
public function getFeed(){
$criteria = $this->getCriteria();
$url = "";
if($criteria["plaats"] != ""){
$url = FriendlyURLs::getCityFeedURL($criteria["plaats"]);
}else if($criteria["provincie"] != ""){
$url = FriendlyURLs::getProvinceFeedURL($criteria["provincie"]);
}
if($url != ""){
$url .= "?min_opp=". $criteria["min_opp"] ."&max_opp=". $criteria["max_opp"];
}
return $url;
}
public function getDescription(){
return "*******.nl zoekresultaat: ". $this->getShortDescription();
}
public function getShortDescription(){
$criteria = $this->getCriteria();
$desc = "";
$extra = "";
if($criteria["max_opp"] != MAXOPP){
$extra = " met een oppervlakte tussen ". $criteria["min_opp"] ."m2 en ". $criteria["max_opp"] ."m2";
}else if($criteria["min_opp"] != 0){
$extra = " met een minimale oppervlakte van ". $criteria["min_opp"] ."m2";
}
if($criteria["plaats"] != ""){
if($criteria["plaatsId"] != -1){
$desc = "kantoorruimte in ". getObjectField($criteria["plaatsId"], "naam").
$extra;
}else{
$desc = "kantoorruimte in ". $criteria["plaats"].
$extra;
}
}else if($criteria["provincie"] != ""){
if($criteria["provincieId"] != -1){
$desc = "kantoorruimte in provincie ". getObjectField($criteria["provincieId"], "naam").
$extra;
}else{
$desc = "kantoorruimte in provincie ". $criteria["provincie"].
$extra;
}
}
return $desc;
}
/**
* All searchcriteria options are stored in fn_object_field_smalltext (for now)
*/
public function showResult(){
if($this->navigation->getPostVar("notify", "string", "") == ""){
$results = $this->getResults();
if(count($results) > 0){
$this->outputResults($results, $this->criteria["pagina"]);
$this->outputPager(count($results), $this->criteria["pagina"]);
}else{
$this->outputNotifyForm();
}
}else{
$this->outputNotifyForm();
}
}
public function getResults(){
$results = array();
$locationIds = array();
if($this->criteria["plaatsId"] != -1){
$locationIds[] = $this->criteria["plaatsId"];
}else if($this->criteria["provincieId"] != -1){
$locationIds = getObjectIdByTemplateFieldValue("plaats", "provincie", $this->criteria["provincieId"]);
}
if(count($locationIds) > 0){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE f.active".
" AND s.tfId = ". getTemplateFieldIdByName("ruimte", "plaats");
if(count($locationIds) > 1){
$sql .= " AND s.value IN (". implode($locationIds, ',') .")";
}else{
$sql .= " AND s.value = ". $locationIds[0];
}
$sql .= " ORDER BY f.creation_date DESC";
$res1 = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res1) > 0){
while($row=mysql_fetch_assoc($res1)){
$results[] = $row["oId"];
}
if($this->criteria["min_opp"] > 0){
$pre = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = ". getTemplateFieldIdByName("ruimte", "oppervlakte minimaal");
if($this->criteria["max_opp"] != MAXOPP && is_numeric($this->criteria["max_opp"])){
/*
get
res1 min gebouw tussen min opp en max opp
res2 max gebouw tussen min opp en max opp, exclude res1
res3 min gebouw < min
res4 max gebouw > max opp IN res4
add to total!
*/
//*** RANGE 1 starting or ending between MIN/MAX
/** first get a temporary result for the minimum area */
$pre .= " AND s.value BETWEEN ". $this->criteria["min_opp"] ." AND ". $this->criteria["max_opp"];
$sql = $pre ." AND f.oId IN (". implode($results, ',') .")".
" ORDER BY f.creation_date DESC";
$totalresults = array();
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
//now check maximum
if(count(array_diff($results, $totalresults)) > 0){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte maximaal")."'".
" AND s.value != ''".
" AND s.value BETWEEN ". $this->criteria["min_opp"] ." AND ". $this->criteria["max_opp"] .
" AND f.oId IN (". implode(array_diff($results, $totalresults), ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
}
//*** RANGE 2 start and end outside MIN/MAX
if(count(array_diff($results, $totalresults)) > 0){
$resOutside = array();
//*** MAX outside
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte maximaal")."'".
" AND s.value != ''".
" AND s.value > ". $this->criteria["max_opp"] .
" AND f.oId IN (". implode(array_diff($results, $totalresults), ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$resOutside[] = $row["oId"];
}
//*** MIN outside
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte minimaal")."'".
" AND s.value != ''".
" AND s.value < ". $this->criteria["min_opp"] .
" AND f.oId IN (". implode($resOutside, ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
}
}
$results = $totalresults;
}else{
$pre .= " AND s.value >= ". $this->criteria["min_opp"];
$sql = $pre ." AND f.oId IN (". implode($results, ',') .")".
" ORDER BY f.creation_date DESC";
$totalresults = array();
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
//now check maximum
if(count(array_diff($results, $totalresults)) > 0){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte maximaal")."'".
" AND (s.value >= ". $this->criteria["min_opp"]." AND s.value != '')".
" AND f.oId IN (". implode( array_diff($results, $totalresults) , ',') .")".
" ORDER BY f.creation_date DESC";
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$totalresults[] = $row["oId"];
}
}
}
$results = $totalresults;
}
}else if($this->criteria["max_opp"] != MAXOPP && is_numeric($this->criteria["max_opp"])){
$sql = "SELECT DISTINCT f.oId".
" FROM fn_object AS f".
" JOIN fn_object_field_smalltext AS s ON f.oId = s.oId".
" WHERE s.tfId = '". getTemplateFieldIdByName("ruimte", "oppervlakte minimaal")."'".
" AND s.value <= ". $this->criteria["max_opp"].
" AND f.oId IN (". implode($results, ',') .")".
" ORDER BY f.creation_date DESC";
$results = array();
$res = mysql_query($sql) or die(mysql_error() ."::". $sql);
if(mysql_num_rows($res) > 0){
while($row=mysql_fetch_assoc($res)){
$results[] = $row["oId"];
}
}
}
}
}
return $results;
}
private function outputResults($results, $page){
$page = ($page > 0)? $page-1 : $page;
$results = array_slice($results, $page*PAGESIZE, PAGESIZE);
echo "<h1>Kantoorruimte huren ". $this->navigation->parsedPlaats() ."</h1>";
echo "<ol id=\"searchresult\">";
$pc = count($results);
for($p=0; $p<$pc; $p++){
$oId = $results[$p];
$city = getObjectField($oId, "plaats");
if($city != -1){
$city = getObjectField($city, "naam");
}
$url = FriendlyURLs::getObjectURL($city, $oId);
?>
<li>
<a href="<?php echo $url ?>" title="Meer informatie / prijsopgave"><div class="thumb"><div class="cover"></div><?php $this->util->outputFirstThumbnail($oId) ?></div></a>
<div class="info">
<h2><?php echo getObjectField($oId, "adres") .", ". getObjectField($oId, "postcode") ?><label><?php echo $city ?></label></h2>
<p>
<?php
$this->outputExcerpt($oId);
?>
</p>
<a href="<?php echo $url ?>">Meer informatie / prijsopgave</a>
</div>
<div class="clear"></div>
</li>
<?php
}
echo "</ol>";
}
private function outputPager($numresults, $page){
echo '<div id="pager">';
if($page > 1){
echo '<a href="'. $this->getLink() ."&pagina=". ($page - 1) .'" class="back"><Terug</a> ';
}
$pages = ceil($numresults / PAGESIZE);
if($pages > 1){
for($p=1; $p<=$pages; $p++){
if($p == $this->criteria["pagina"]){
echo "<strong>$p</strong>";
}else{
echo '<a href="'. $this->getLink() .'&pagina='. $p .'">'. $p .'</a> ';
}
if($p != $pages){
echo "| ";
}
}
}
if($page < $pages){
echo '<a href="'. $this->getLink() ."&pagina=". ($page + 1) .'" class="forward">Verder></a> ';
}
echo "</div>";
}
private function outputNotifyForm($showIntro = true){
require_once("class.form.php");
$notifyForm = new SearchRequestForm($this->navigation);
$parsed = false;
if($notifyForm->posted()){
$parsed = $notifyForm->parse($this);
}
if($parsed){
$notifyForm->finished();
}else{
$notifyForm->show($this);
}
}
private function outputExcerpt($oId){
$text = strip_tags(getObjectField($oId, "omschrijving"));
if(strlen($text) > 350){
echo substr($text, 0, 350)."...";
}else{
echo $text;
}
}
}
?>
Gewijzigd op 18/05/2010 00:04:50 door Peps from Yesterday
Zou je en tags om je code willen zetten?
heb je ook een idee waarin ik dat moet veranderen?
Hartelijk bedankt voor alle hulp! het is gelukt! het was idd een kwestie van creation_date aanpassen, had de goede colom opgezocht in de database, en vervangen.
een reverse array erover en klaar! perfect!
Dank jullie wel!
array_reverse erover gooit dan kan je waarschijnlijk net zo goed die DESC vervangen in ASC
Als je Hartelijk bedankt nogmaals!