Functie lijkt een array niet te zien

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Simon Teeninga

Simon Teeninga

26/12/2015 21:58:53
Quote Anchor link
Allereerst, fijne kerst nog ff!

Ik heb een probleem geminimaliseerd tot het volgende stukje code.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
$item
= array();
$item[] = array("HL","03-09-2016","http://www.loopcircuitdewolden.nl/"," ","Dijkhuizenrun");
$item[] = array("HL","03-09-2016","http://www.avaquilo.nl"," ","Jaarmarktloop");

$event = array();
for($i=0;$i<sizeof($item);$i++):
    $event[$item[$i][1]][] = array($item[$i][0],$item[$i][2],$item[$i][4]);
endfor;

print @$event["03-09-2016"][0][2];        //prints Dijkhuizenrun

function blabla()
{

return @$event["03-09-2016"][0][2];        //can't find entry
}

print blabla();                    //so.. prints nothing
?>


Wat zie ik over het hoofd?

Groet,
Simon
Gewijzigd op 26/12/2015 22:19:09 door Simon Teeninga
 
PHP hulp

PHP hulp

14/11/2024 04:36:02
 
Ben van Velzen

Ben van Velzen

26/12/2015 22:56:04
Quote Anchor link
Je ziet de scoping over het hoofd. Je kunt global $event gebruiken in je functie, maar het is netter op $event bijvoorbeeld mee te geven aan de functie.
Als je die vreselijke @ niet gebruikt zie je ook duidelijk een melding over een undefined variable.
Gewijzigd op 26/12/2015 23:08:34 door Ben van Velzen
 
Simon Teeninga

Simon Teeninga

26/12/2015 23:11:38
Quote Anchor link
Ik zit nog steeds met hetzelfde probleem, misschien weet ik niet goed wat je bedoelt met scoping.
Zo?:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?
function blabla()
{

global $a;
$a = @$event["03-09-2016"][0][2];
return $a;
}

?>

Want ook dat werkt niet (ik neem aan dat ik het niet goed doe).

- Wat betreft de datum meegeven aan de functie, dat gaat niet:
De originele functie print een kalendermaand in een tabel. Met een for-loop voor bijv. 2016 voert hij deze functie 12x uit in de vorm van create_calender(12,2016). Bij iedere dag (bijv. 03-09-2016) wil ik checken of er een evenement is gepland die dag. Maar hij kan het niet lezen. Het probleem zit hem ergens in het bovenstaande voorbeeld. Ik kan het hele geval posten, maar weet niet of je daar meer mee kunt.

- Wat betreft je opmerking over die @: ik zal er iets anders op verzinnen. Maar dat heeft geen effect op de uitvoer (helaas geen melding over lege variabelen in het complete script). En ik heb met opzet ook buiten de functie dezelfde opdracht staan waar die wel werkt.

Bedankt voor je reactie en het meedenken.

Toevoeging op 26/12/2015 23:16:33:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<html>
<head>
<style>
/* calendar */
table.calendar        { border-left:1px solid #999; }
tr.calendar-row        {  }
td.calendar-day        { min-height:160px; font-size:10px; position:relative; } * html div.calendar-day { height:160px; }
td.calendar-day:hover    { background:#ece5ff; }
td.calendar-day-np    { background:#eee; min-height:160px; } * html div.calendar-day-np { height:160px; }
td.calendar-day-head     { font-family:verdana; font-size:12px; background:#ccc; font-weight:bold; text-align:center; width:200px; padding:5px; border-bottom:1px solid #999; border-top:1px solid #999; border-right:1px solid #999; }
div.day-number        { font-family:verdana; font-size:14px; background:#999; padding:5px; color:#fff; font-weight:bold; float:right; margin:-5px -5px 0 0; width:20px; text-align:center; }
/* shared */
td.calendar-day, td.calendar-day-np { width:200px; padding:5px; border-bottom:1px solid #999; border-right:1px solid #999; }
/* month + year */
h2             { font-family:verdana; font-size:16px; }
</style>
</head>
<body>
<?php
$item
= array();
// $item[] = array("CAT","Datum","Link","","Naam","Vertrekplaats","Afstand","Tijd","Opmerking","Ingeschreven","Staat Datum Vast");
$item[] = array("HL","27-12-2015","http://www.avaquilo.nl/index.php/weg-a-recreatiefalgemeen/w-a-r-artikels/775-oudejaarsloop2015"," ","Valkema Sport Oudejaarsloop","Blijham","HM","","Loopcircuit Schutrups","Ja","Ja");
$item[] = array("HL","02-01-2016","http://www.runnersstadskanaal.nl/index.php?page=691&sid=2"," ","Noorderpoort Nieuwjaarsloop","Stadskanaal","10K","","Loopcircuit Schutrups","Ja","Ja");
$item[] = array("HL","14-02-2016","http://www.groetuitschoorl.nl/algemeen-10-km/"," ","Groet uit Schoorl","Schoorl","10K","","Inschrijven vanaf 24 augustus 2015","","Ja");
$item[] = array("HL","26-03-2016","http://www.loopcircuitdewolden.nl/"," ","Viaductenloop","Zuidwolde","10K","","Loopcircuit De Wolden","","");
$item[] = array("HL","10-04-2016","http://www.nnmarathonrotterdam.nl/"," ","NN Marathon Rotterdam","Rotterdam","M","","","Ja","Ja");
$item[] = array("HL","17-04-2016","http://www.cascaderun.nl/nl/deelnemers-bedrijventeams/individuele-deelnemers/"," ","Cascaderun","Hoogeveen","5EM","","","","Ja");
$item[] = array("HL","05-05-2016","http://www.nachtvangroningen.nl/"," ","Nacht van Groningen","Groningen","10K","","","","");
$item[] = array("HL","07-05-2016","http://www.loopcircuitdewolden.nl/"," ","Crossloop","Zuidwolde","10K","","Loopcircuit De Wolden","","");
$item[] = array("HL","18-05-2016","http://www.acerflanden.nl/erflandenrun/"," ","Erflandenrun","Hoogeveen","10K","","","","");
$item[] = array("HL","22-05-2016","http://www.loopleeuwarden.frl/hardlopen/"," ","Loop van Leeuwarden","Leeuwarden","10K","","Inschrijving geopend","","Ja");
$item[] = array("HL","29-05-2016","www.svveendamatletiek.nl"," ","Valkema Parkstadloop","Veendam","10K","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","05-06-2016","http://www.loopcircuitdewolden.nl/"," ","Mooi Ruinen Run","Ruinen","10K","","Loopcircuit De Wolden","","");
$item[] = array("HL","08-06-2016","http://www.avaquilo.nl"," ","Oud Alteveerloop","Nieuwe Pekela","10K","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","12-06-2016","http://run4.educaided.org/"," ","Run4Educaided","Groningen","4EM","","","","Ja");
$item[] = array("HL","19-06-2016","www.svveendamatletiek.nl"," ","Natuurloop Meerwijck","Kropswolde","10K","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","25-06-2016","http://www.univestadsloop.nl/"," ","Unive Stadsloop","Appingedam","10K","","","","");
$item[] = array("HL","25-06-2016","http://www.runnersstadskanaal.nl"," ","Onstwedderomloop","Onstwedde","10K","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","10-08-2016","http://www.loopcircuitdewolden.nl/"," ","Alkeloop","Alteveer","10K","","Loopcircuit De Wolden","","");
$item[] = array("HL","20-08-2016","http://www.desnellerakkers.nl/Singelloop/Singelloop.php"," ","Singelloop","Hollandscheveld","10K","","","","");
$item[] = array("HL","25-08-2016","http://www.loopcircuitdewolden.nl/"," ","Wiekloop","De Wijk","10K","","Loopcircuit De Wolden","","");
$item[] = array("HL","03-09-2016","http://www.loopcircuitdewolden.nl/"," ","Dijkhuizenrun","Ruinerwold","10K","","Loopcircuit De Wolden","","");
$item[] = array("HL","03-09-2016","http://www.avaquilo.nl"," ","Jaarmarktloop","Oude Pekela","10K","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","10-09-2016","http://www.runwinschoten.nl/"," ","Run Winschoten","Winschoten","10K","","","","");
$item[] = array("HL","18-09-2016","http://www.damloop.nl/"," ","Dam tot Damloop","Amsterdam","10EM","","","","Ja");
$item[] = array("HL","25-09-2016","http://www.runnersstadskanaal.nl"," ","Schutrups Run","Exloo","HM","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","02-10-2016","http://www.loopcircuitdewolden.nl/"," ","Bikkelloop","Zuidwolde","10K","","Loopcircuit De Wolden","","");
$item[] = array("HL","09-10-2016","http://4mijl.nl/"," ","4Mijl van Groningen","Groningen","4EM","","","","Ja");
$item[] = array("HL","23-10-2016","http://zeemijlenloopdelfzijl.nl/"," ","Zeemijlenloop","Delfzijl","6ZM","","","","");
$item[] = array("HL","29-10-2016","http://avdcross.nl/category/nieuws/"," ","Dwingelderveldloop","Dwingeloo","HM","","","","");
$item[] = array("HL","06-11-2016","http://www.runnersstadskanaal.nl"," ","Polderputten Bosloop","Ter Apel","10K","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","12-11-2016","http://www.avaquilo.nl"," ","Virol Sinterklaasloop","Scheemda","10K","","Loopcircuit Schutrups","Ja","");
$item[] = array("HL","20-11-2016","http://www.zevenheuvelenloop.nl/"," ","Zevenheuvelenloop","Nijmegen","15K","","Inschrijven vanaf 1 juni 2016","","Ja");
$item[] = array("HL","18-12-2016","http://www.avaquilo.nl"," ","Valkema Sport Oudejaarsloop","Blijham","HM","","Loopcircuit Schutrups","Ja","");

    /* rearrange the array to event["Datum"][] = array("0CAT","1Link","2Naam","3Vertrekplaats","4Afstand","5Tijd","6Opmerking","7Ingeschreven","8Staat Datum Vast"); to make it searchable */
    /* second bracket for double events on a date like on the 3rd of sep */


    $event = array();
    for($i=0;$i<sizeof($item);$i++):
        $event[$item[$i][1]][] = array($item[$i][0],$item[$i][2],$item[$i][4],$item[$i][5],$item[$i][6],$item[$i][7],$item[$i][8],$item[$i][9],$item[$i][10]);
    endfor;
$test_1 = '03';
$test_2 = '09';
$test_3 = '2016';
$test_4 = $test_1.'-'.$test_2.'-'.$test_3;
/*************************WERKT PRIMA*********************************/
print '<p>'.@$event[$test_4][0][2].'</p>';

$months = array('Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December');
/* draws a calendar */
function draw_calendar($month,$year){

    /* draw table */
    $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';

    /* table headings */
    $headings = array('Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag');
    $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';

    /* days and weeks vars now ... */
    $running_day = date('w',mktime(0,0,0,$month,1,$year));
    $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
    $days_in_this_week = 1;
    $day_counter = 0;
    $dates_array = array();

    /* row for week one */
    $calendar.= '<tr class="calendar-row">';

    /* print "blank" days until the first of the current week */
    for($x = 0; $x < $running_day; $x++):
        $calendar.= '<td class="calendar-day-np"> </td>';
        $days_in_this_week++;
    endfor;

    /* keep going with days.... */
    for($list_day = 1; $list_day <= $days_in_month; $list_day++):
        $calendar.= '<td class="calendar-day">';
        
        /* add in the day number */
        $calendar.= '<div class="day-number">'.$list_day.'</div>';

        /* make the date */
        $list_day < 10 ? $dag = '0'.$list_day : $dag = $list_day;
        $month < 10 ? $maand = '0'.$month : $maand = $month;
        $jaar = ''.$year;

        /* list the events (2nd entry in array) with that key */
        $datekey = $dag.'-'.$maand.'-'.$jaar;

        /***************EN HIER ZIT HET PROBLEEM**************/
        $calendar.='<p>'.@$event[$datekey][0][2].'</p>';    
        /*********************DOET NIE***********************/

        $calendar.= '</td>';
        if($running_day == 6):
            $calendar.= '</tr>';
            if(($day_counter+1) != $days_in_month):    
                $calendar.= '<tr class="calendar-row">';
            endif;

            $running_day = -1;
            $days_in_this_week = 0;
        endif;

        $days_in_this_week++; $running_day++; $day_counter++;
    endfor;

    /* finish the rest of the days in the week */
    if($days_in_this_week < 8 && $days_in_this_week > 1):
        for($x = 1; $x <= (8 - $days_in_this_week); $x++):
            $calendar.= '<td class="calendar-day-np"> </td>';
        endfor;
    endif;


    /* final row */
    $calendar.= '</tr>';

    /* end the table */
    $calendar.= '</table>';
    
    /* all done, return result */
    return $calendar;
}


/* well now, we can easily work with request variables: */
/* but let's start with only the last month in 2015 (bc of Schutrups final run) */

for($i=11;$i<12;$i++):
print '<h2>'.$months[$i].' 2015</h2>';
print draw_calendar($i+1,2015);
endfor;

/* and continue with the complete year of 2016 */
for($i=0;$i<12;$i++):
print '<h2>'.$months[$i].' 2016</h2>';
print draw_calendar($i+1,2016);
endfor;
?>

</body>
</html>
Gewijzigd op 26/12/2015 23:26:25 door Simon Teeninga
 
Thomas van den Heuvel

Thomas van den Heuvel

26/12/2015 23:27:06
Quote Anchor link
$event is niet bekend binnen de functie.
 
Ben van Velzen

Ben van Velzen

26/12/2015 23:27:46
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?
function blabla()
{

global $a;
$a = @$event["03-09-2016"][0][2];
return $a;
}

?>


Dat zei ik toch niet? Ik bedoelde
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
<?
function blabla()
{

global $event;
return $event["03-09-2016"][0][2];
}

?>


Of nog liever
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?
function blabla($event)
{

return $event["03-09-2016"][0][2];
}

?>
 
Thomas van den Heuvel

Thomas van den Heuvel

26/12/2015 23:31:45
Quote Anchor link
Ben van Velzen op 26/12/2015 23:27:46:
Of nog liever
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?
function blabla($event)
{

return $event["03-09-2016"][0][2];
}

?>

Euh, functies zouden herbruikbaar moeten zijn, ik zou dan op zijn minst ook een datum parameter verwachten, zodanig dat "blabla" alle events op die datum teruggeeft ofzo. Functies zouden een zekere toegevoegde waarde moeten hebben.
 
Simon Teeninga

Simon Teeninga

26/12/2015 23:36:25
Quote Anchor link
Nee Ben, dat zei je ook niet, dat maakte ik er van in al mijn onkunde.

Hoe dan ook; nu print hij inderdaad wel! Ik sta te trappelen om het in de originele code te proberen........ brb.
 
Ben van Velzen

Ben van Velzen

26/12/2015 23:36:54
Quote Anchor link
Mee eens, maar het gaat mij vooral om het wegwerken van die global. Ik ga er vanuit dat Simon weet hoe je functies hoort op te bouwen.
 
Simon Teeninga

Simon Teeninga

26/12/2015 23:37:30
Quote Anchor link
F**K YEAH.

Scoping dus.

Thanks a million!

Toevoeging op 26/12/2015 23:41:57:

Wat ik in eerste instantie postte was misschien niet netjes (zie originele code, dan zie je wel parameters). Maar het probleem was duidelijk en de oplossing nu ook.

Ik kan me niet herinneren dat het vroegah wat uitmaakte met dat scoping. Het werd wel 'netjes' bevonden, maar het parsen was vergevingsgezind.

Nogmaals dank!
 
Ozzie PHP

Ozzie PHP

26/12/2015 23:58:45
Quote Anchor link
PS

Kijk eens naar een foreach constructie in plaats van die lastige constructie in je for loop die je nu gebruikt.
 
Simon Teeninga

Simon Teeninga

27/12/2015 01:21:31
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?
for($i=0;$i<sizeof($item);$i++):
        $event[$item[$i][1]][] = array($item[$i][0],$item[$i][2],$item[$i][4],$item[$i][5],$item[$i][6],$item[$i][7],$item[$i][8],$item[$i][9],$item[$i][10]);
    endfor;
?>


OK, zo dan:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?
foreach($item as $e)
{

  $event[$e[1]][] = array($e[0],$e[2],$e[4],$e[5],$e[6],$e[7],$e[8],$e[9],$e[10]);
}

?>


Heb mezelf ooit wijsgemaakt dat het met arrays in arrays in arrays altijd knap ingewikkeld kan zijn met de foreach functie, zit dan telkens de print_r functie te gebruiken om uit te lezen wat ik dan weer fout doe .... heb meer overzicht met for. In dit geval lag foreach natuurlijk meer voor de hand.

Thanks.
 
Ozzie PHP

Ozzie PHP

27/12/2015 01:26:51
Quote Anchor link
Ik weet niet precies wat je hierboven doet en hoe jouw code in elkaar steekt, maar bij een foreach loop kun je gebruikmaken van een KEY en een VALUE. Dat kan wellicht handig zijn.

Daarnaast weet ik eigenlijk ook niet wat je eigenlijk probeert te doen. Het lijkt alsof je nu gewoon de ene array in de andere aan het stoppen bent. Wat is precies je bedoeling?
 
Simon Teeninga

Simon Teeninga

27/12/2015 01:36:50
Quote Anchor link
De eerste rij arrays zijn automatisch geimporteerd ($item).

De kalender wordt per dag opgebouwd. Op een gegeven moment is de datum bijv. 12-06-2016.
Ik wil kijken of er op die dag een evenement is om daar dan de naam enz. van weer te geven.

I.p.v. iedere keer alle evenementen af te gaan met array_search o.i.d., leek het me makkelijker om in 1x een nieuwe array te maken waarbij de datum de KEY is van een nieuwe array, dus dan krijg je een hoop evenementen die er zo uitzien
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?
$event
["12-06-2006"][] = array("naam evenement","locatie","enz");
$event["19-06-2006"][] = array("naam evenement","locatie","enz");
// enz
// per datum kunnen meerdere evenementen zijn, vandaar weer die [] achter de key

?>


Op dat moment kan ik een evenement makkelijk oproepen.

Maar goed.. er zijn altijd gemakkelijkere manieren, en waarschijnlijk komt er zo iemand langs die zegt dat ik MySQL moet gebruiken...... maar ik moest even snel iets in elkaar zetten en ben geen webdesigner of programmeur, dus het is wel even goed zo :).

Thanks.
Gewijzigd op 27/12/2015 01:38:57 door Simon Teeninga
 
Ozzie PHP

Ozzie PHP

27/12/2015 01:52:12
Quote Anchor link
Waarom stop je dan niet de complete array erin (in plaats van losse waarden). Daarmee wordt je code overzichtelijker en korter:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?php
$items
  = array(); // let op de s bij $items, een array bevat meerdere items
$events = array(); // ook hier weer een s, want meerdere events in een array

foreach($items as $event) {
    $events[$event[1]][] = $event;
}

?>
 
Simon Teeninga

Simon Teeninga

27/12/2015 02:20:33
Quote Anchor link
Ik heb volgens mij alle tips ter harte genomen, dank dank dank.

Ben nog wel even bezig met mijn projectje, maar stap 1 is er. Het volgende werkt nu:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<html>
<head>
<style>
/* calendar */
table.calendar        { border-left:1px solid #999; }
tr.calendar-row        {  }
td.calendar-day        { min-height:200px; font-family:verdana; font-size:10px; padding-left:10px; position:relative; } * html div.calendar-day { height:200px; }
td.calendar-day:hover    { background:#ece5ff; }
td.calendar-day-np    { background:#eee; min-height:200px; } * html div.calendar-day-np { height:200px; }
td.calendar-day-head     { font-family:verdana; font-size:14px; background:#ccc; font-weight:bold; text-align:center; width:250px; padding:5px; border-bottom:1px solid #999; border-top:1px solid #999; border-right:1px solid #999; }
div.day-number        { font-family:verdana; font-size:16px; background:#33F; padding:0px; color:#fff; font-weight:bold; float:right; vertical-align:top; margin:-5px -5px 0 0; margin-top:0; width:25px; height:100px; text-align:center; }
/* shared */
td.calendar-day, td.calendar-day-np { width:250px; padding:5px; border-bottom:1px solid #999; border-right:1px solid #999;height:100px; }
/* month + year */
h2             { font-family:verdana; font-size:16px; }
hr            { thin solid #000; }
</style>
</head>
<body>
<?php
$items
= array();
$events = array();
// $items[] = array("CAT","Datum","Link","","Naam","Vertrekplaats","Afstand","Tijd","Opmerking","Ingeschreven","Staat Datum Vast");
$items[] = array("VAK","27-02-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","28-02-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","29-02-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","01-03-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","02-03-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","03-03-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","04-03-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","05-03-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","06-03-2016",""," ","Voorjaarsvakantie","","","","","","Ja");
$items[] = array("VAK","28-03-2016",""," ","Pasen","","","","","","");
$items[] = array("VAK","27-04-2016",""," ","Koningsdag","","","","","","");
$items[] = array("VAK","30-04-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","01-05-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","02-05-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","03-05-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","04-05-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","05-05-2016",""," ","Hemelvaartsdag","","","","","","");
$items[] = array("VAK","06-05-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","07-05-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","08-05-2016",""," ","Meivakantie","","","","","","Ja");
$items[] = array("VAK","16-05-2016",""," ","Pinksteren","","","","","","");
$items[] = array("VAK","16-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","17-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","18-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","19-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","20-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","21-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","22-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","23-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","24-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","25-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","26-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","27-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","28-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","29-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","30-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","31-07-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","01-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","02-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","03-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","04-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","05-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","06-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","07-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","08-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","09-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","10-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","11-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","12-08-2016",""," ","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","13-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","14-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","15-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","16-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","17-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","18-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","19-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","20-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","21-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","22-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","23-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","24-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","25-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","26-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","27-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","28-08-2016","","","Zomervakantie","","","","","","Ja");
$items[] = array("VAK","15-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","16-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","17-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","18-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","19-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","20-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","21-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","22-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","23-10-2016","","","Herfstvakantie","","","","","","Ja");
$items[] = array("VAK","24-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","25-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","26-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","27-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","28-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","29-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","30-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","31-12-2016","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","01-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","02-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","03-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","04-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","05-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","06-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","07-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("VAK","08-01-2017","","","Kerstvakantie","","","","","","");
$items[] = array("SK","27-02-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("SK","28-02-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("SK","29-02-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("SK","01-03-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("SK","02-03-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("SK","03-03-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("SK","04-03-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("SK","05-03-2016",""," ","Wintersport","Wagrain","","","","","Ja");
$items[] = array("AJ","23-01-2016",""," ","Ajax-Vitesse","Amsterdam","","","19:45","","");
$items[] = array("AJ","26-01-2016",""," ","Ajax-Heracles","Amsterdam","","","20:45","","");
$items[] = array("AJ","07-02-2016",""," ","Ajax-Feyenoord","Amsterdam","","","12:30","","");
$items[] = array("AJ","21-02-2016",""," ","Ajax-Excelsior","Amsterdam","","","14:30","","");
$items[] = array("AJ","28-02-2016",""," ","Ajax-AZ","Amsterdam","","","16:45","","");
$items[] = array("AJ","13-03-2016",""," ","Ajax-NEC","Amsterdam","","","16:45","","");
$items[] = array("AJ","20-03-2016",""," ","PSV-Ajax","Groningen","","","16:45","","");
$items[] = array("AJ","03-04-2016",""," ","Ajax-Zwolle","Amsterdam","","","16:45","","");
$items[] = array("AJ","17-04-2016",""," ","Ajax-Utrecht","Amsterdam","","","12:30","","");
$items[] = array("AJ","01-05-2016",""," ","Ajax-FC Twente","Amsterdam","","","14:30","","");
$items[] = array("HL","02-01-2016","http://www.runnersstadskanaal.nl/index.php?page=691&sid=2"," ","Noorderpoort Nieuwjaarsloop","Stadskanaal","10K","","Loopcircuit Schutrups","Ja","Ja");
$items[] = array("HL","14-02-2016","http://www.groetuitschoorl.nl/algemeen-10-km/"," ","Groet uit Schoorl","Schoorl","10K","","Inschrijven vanaf 24 augustus 2015","","Ja");
$items[] = array("HL","26-03-2016","http://www.loopcircuitdewolden.nl/"," ","Viaductenloop","Zuidwolde","10K","","Loopcircuit De Wolden","","");
$items[] = array("HL","10-04-2016","http://www.nnmarathonrotterdam.nl/"," ","NN Marathon Rotterdam","Rotterdam","M","","","Ja","Ja");
$items[] = array("HL","17-04-2016","http://www.cascaderun.nl/nl/deelnemers-bedrijventeams/individuele-deelnemers/"," ","Cascaderun","Hoogeveen","5EM","","","","Ja");
$items[] = array("HL","05-05-2016","http://www.nachtvangroningen.nl/"," ","Nacht van Groningen","Groningen","10K","","","","");
$items[] = array("HL","07-05-2016","http://www.loopcircuitdewolden.nl/"," ","Crossloop","Zuidwolde","10K","","Loopcircuit De Wolden","","");
$items[] = array("HL","18-05-2016","http://www.acerflanden.nl/erflandenrun/"," ","Erflandenrun","Hoogeveen","10K","","","","");
$items[] = array("HL","22-05-2016","http://www.loopleeuwarden.frl/hardlopen/"," ","Loop van Leeuwarden","Leeuwarden","10K","","Inschrijving geopend","","Ja");
$items[] = array("HL","29-05-2016","www.svveendamatletiek.nl"," ","Valkema Parkstadloop","Veendam","10K","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","05-06-2016","http://www.loopcircuitdewolden.nl/"," ","Mooi Ruinen Run","Ruinen","10K","","Loopcircuit De Wolden","","");
$items[] = array("HL","08-06-2016","http://www.avaquilo.nl"," ","Oud Alteveerloop","Nieuwe Pekela","10K","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","12-06-2016","http://run4.educaided.org/"," ","Run4Educaided","Groningen","4EM","","","","Ja");
$items[] = array("HL","19-06-2016","www.svveendamatletiek.nl"," ","Natuurloop Meerwijck","Kropswolde","10K","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","25-06-2016","http://www.univestadsloop.nl/"," ","Unive Stadsloop","Appingedam","10K","","","","");
$items[] = array("HL","25-06-2016","http://www.runnersstadskanaal.nl"," ","Onstwedderomloop","Onstwedde","10K","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","10-08-2016","http://www.loopcircuitdewolden.nl/"," ","Alkeloop","Alteveer","10K","","Loopcircuit De Wolden","","");
$items[] = array("HL","20-08-2016","http://www.desnellerakkers.nl/Singelloop/Singelloop.php"," ","Singelloop","Hollandscheveld","10K","","","","");
$items[] = array("HL","25-08-2016","http://www.loopcircuitdewolden.nl/"," ","Wiekloop","De Wijk","10K","","Loopcircuit De Wolden","","");
$items[] = array("HL","03-09-2016","http://www.loopcircuitdewolden.nl/"," ","Dijkhuizenrun","Ruinerwold","10K","","Loopcircuit De Wolden","","");
$items[] = array("HL","03-09-2016","http://www.avaquilo.nl"," ","Jaarmarktloop","Oude Pekela","10K","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","10-09-2016","http://www.runwinschoten.nl/"," ","Run Winschoten","Winschoten","10K","","","","");
$items[] = array("HL","18-09-2016","http://www.damloop.nl/"," ","Dam tot Damloop","Amsterdam","10EM","","","","Ja");
$items[] = array("HL","25-09-2016","http://www.runnersstadskanaal.nl"," ","Schutrups Run","Exloo","HM","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","02-10-2016","http://www.loopcircuitdewolden.nl/"," ","Bikkelloop","Zuidwolde","10K","","Loopcircuit De Wolden","","");
$items[] = array("HL","09-10-2016","http://4mijl.nl/"," ","4Mijl van Groningen","Groningen","4EM","","","","Ja");
$items[] = array("HL","23-10-2016","http://zeemijlenloopdelfzijl.nl/"," ","Zeemijlenloop","Delfzijl","6ZM","","","","");
$items[] = array("HL","29-10-2016","http://avdcross.nl/category/nieuws/"," ","Dwingelderveldloop","Dwingeloo","HM","","","","");
$items[] = array("HL","06-11-2016","http://www.runnersstadskanaal.nl"," ","Polderputten Bosloop","Ter Apel","10K","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","12-11-2016","http://www.avaquilo.nl"," ","Virol Sinterklaasloop","Scheemda","10K","","Loopcircuit Schutrups","Ja","");
$items[] = array("HL","20-11-2016","http://www.zevenheuvelenloop.nl/"," ","Zevenheuvelenloop","Nijmegen","15K","","Inschrijven vanaf 1 juni 2016","","Ja");
$items[] = array("HL","18-12-2016","http://www.avaquilo.nl"," ","Valkema Sport Oudejaarsloop","Blijham","HM","","Loopcircuit Schutrups","Ja","");

/* rearrange the array to event["Datum"][] = array("0CAT","1Link","2Naam","3Vertrekplaats","4Afstand","5Tijd","6Opmerking","7Ingeschreven","8Staat Datum Vast"); to make it searchable */
/* second bracket for double events on a date like on the 3rd of sep */


foreach($items as $event)
{

    $events[$event[1]][] = $event;
}



$afstand = array('5K'=>5000,'4EM'=>6436,'5EM'=>8045,'10K'=>10000,'6ZM'=>11112,'15K'=>15000,'10EM'=>16090,'HM'=>21098,'M'=>42195);

$months = array('Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December');
/* draws a calendar */
function draw_calendar($month,$year)
{


    /* draw table */
    $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';

    /* table headings */
    $headings = array('Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag');
    $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';

    /* days and weeks vars now ... */
    $running_day = date('w',mktime(0,0,0,$month,1,$year));
    $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
    $days_in_this_week = 1;
    $day_counter = 0;
    $dates_array = array();

    /* row for week one */
    $calendar.= '<tr class="calendar-row">';

    /* print "blank" days until the first of the current week */
    for($x = 0; $x < $running_day; $x++)
    {

        $calendar.= '<td class="calendar-day-np"> </td>';
        $days_in_this_week++;
    }


    /* keep going with days.... */
    for($list_day = 1; $list_day <= $days_in_month; $list_day++)
    {

        $calendar.= '<td class="calendar-day">';
        
        /* add in the day number */
        $calendar.= '<div class="day-number">'.$list_day.'</div>';

        /* make the date */
        $list_day < 10 ? $dag = '0'.$list_day : $dag = $list_day;
        $month < 10 ? $maand = '0'.$month : $maand = $month;
        $jaar = ''.$year;

        /* list the events (2nd entry in array) with that key */
        $datekey = $dag.'-'.$maand.'-'.$jaar;

        global $events;
        global $afstand;
        for($x=0;$x<sizeof($events[$datekey]);$x++)
        {

            $e = $events[$datekey][$x];

            // HARDLOOPEVENEMENT
            if($e[0] == 'HL')
            {

                $e[10] == "Ja" ? $ozh = "<font color=green></font>" : $ozh = "<font color=red>Datum onzeker</font>";

                $calendar.='<p><b><a href="'.$e[2].'" title="
'
.$e[4].' ('.$e[6].')
'
.$e[8].'">'.$e[4].'</a><br/>'.$afstand[$e[6]].'m '.$ozh.'</b></p>';
    
            }


            else
            {
                $clr = '';
                switch($e[0])
                {
                    case
'AJ' : $clr = 'red'; break;
                    case
'VAK' : $clr = 'green'; break;
                    case
'SK' : $clr = 'orange'; break;
                }

                // OVERIG
                $calendar.='<p><b><font color='.$clr.'>'.$e[4].'</font></b></p>';
            }

        }


        $calendar.= '</td>';
    
        if($running_day == 6)
        {

                $calendar.= '</tr>';
                if(($day_counter+1) != $days_in_month)
                {

                    $calendar.= '<tr class="calendar-row">';
                }

                $running_day = -1;
                $days_in_this_week = 0;
        }

                $days_in_this_week++; $running_day++; $day_counter++;
    }


    /* finish the rest of the days in the week */
    if($days_in_this_week < 8 && $days_in_this_week > 1)
    {

        for($x = 1; $x <= (8 - $days_in_this_week); $x++)
        {

            $calendar.= '<td class="calendar-day-np"> </td>';
        }
    }


    /* final row */
    $calendar.= '</tr>';

    /* end the table */
    $calendar.= '</table>';
    
    /* all done, return result */
    return $calendar;
}


/* well now, we can easily work with request variables */
/* forget about 2015 */
/* and continue with the complete year of 2016 */

for($i=0;$i<12;$i++)
{

    echo '<h2>'.$months[$i].' 2016</h2>';
    echo draw_calendar($i+1,2016);
}

?>

</body>
</html>
Gewijzigd op 27/12/2015 02:21:42 door Simon Teeninga
 
Ozzie PHP

Ozzie PHP

27/12/2015 02:57:35
Quote Anchor link
Kijk, dat ziet er inderdaad al een stuk beter uit!
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.