Lastig probleem met gebruik van array's

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

George van Baasbank

George van Baasbank

04/03/2014 22:14:04
Quote Anchor link
Hallo allemaal,

Ik zit met een lastig probleem.
Ik heb een agenda ontwikkeld. De gebruiker kan, in principe, een oneindig aantal afspraken binnen één uur maken.
Nu is het zo dat als er meerdere boekingen binnen hetzelfde uur zijn, er maar één wordt getoond. Zie onderstaand voorbeeld

Ik weet dat het lastig is om de fout te vinden maar toch probeer ik bij jullie wat suggesties voor een oplossing te vinden.

De php-code voor het uitlezen van de agenda-tabel
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
if($_GET['datum']) {
    $dGekozenDatum = $_GET['datum'];
    $_SESSION['gekozendatum'] = $dGekozenDatum;
    include "include/connectie.inc.php";
    $sql = "select a.*, p.voornaam,p.tussenvoeg,p.achternaam from sys__agenda as a left join pod__profiel as p on a.auditant = p.id where a.datum = '$dGekozenDatum' ORDER BY a.aanvang ASC";
    $cResultUur = mysqli_query($verbinding,$sql);
    mysqli_close($verbinding);
}


De html-code voor het maken van de pagina
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
<body>
    <div class="main-container">
        <?php include "include/header.inc.php" ; ?>
    </div>
    
    <a href="es-agenda.php#bovenaan"><div class="vaste_tab_links">
        <div class="tekst90graden"><?php echo $cExitMelding ; ?></div>
    </div>
    
    <div class="main-container">
        <div class="container1">
            <article class="box2" id="home_featured21">
                <a id="bovenaan"></a>
                <p class="headertekst">Dagindeling <?php echo VolleDatum($dGekozenDatum) ; ?></p>
                <div class="box3">
                    
                    <form action="es-dag.php#bovenaan" method="POST">
                        <div class="marge_knoppen_links">
                            <input type="submit" name="actie" value="<?php echo $cKnop1 ; ?>" />
                            <input type="submit" name="actie" value="<?php echo $cKnop2 ; ?>" />
                        </div>
                    </form>
                    <?php
                        $nVert
= 0;
                        $nVertMax = 24;
                        $aDatum = array();
                        $aUitleg = array();
                        $aAanvang = array();
                        $aAuditant = array();
                        $aEinde = array();
                        $aIdnr = array();
                        $nArrayTeller = 0;

                        while($rowUur    = mysqli_fetch_array($cResultUur)) {
                            $aDatum[]    = $rowUur['datum'];
                            $aUitleg[]   = $rowUur['onderwerp'];
                            $aAanvang[]  = $rowUur['aanvang'];
                            $aEinde[]    = $rowUur['einde'];
                            $aIdnr[]     = $rowUur['id'];
                            $aAuditant[] = $rowUur['voornaam'] . " " . $rowUur['tussenvoeg'] . " " . $rowUur['achternaam'];
                            $aIdAuditant[] = $rowUur['auditant'];
                            $nArrayTeller++;
                        }

                        
                        while($nVert < $nVertMax) {
                            $cAanvangstijd = sprintf('%02d:00:00', $nVert);
                            if(substr($aAanvang[$key],0,2) > 0 AND substr($aAanvang[$key],0,2) < 10) {
                                $cTest = "0" . substr($aAanvang[$key],0,1);
                            }
else {
                                $cTest = substr($aAanvang[$key],0,2);
                            }

                            
                            if(substr($cAanvangstijd,0,2) == $cTest){
                                $nHoogte = ($nArrayTeller * 30) . "px";
                            }
else {
                                $nHoogte = "30px";
                            }

                    ?>

                    
                    <div class="ag_dagindeling_1" style="height: <?php echo $nHoogte ; ?>;">
                        <?php echo $nVert . " uur" ; ?>
                    </div>
                    
                    <div class="ag_dagindeling_2" style="height: <?php echo $nHoogte ; ?>;">
                        <?php
                            $nAfteller
= 0;
                            $key = array_search($cAanvangstijd,$aAanvang);
                            while($nAfteller < $nArrayTeller) {
                                if(substr($cAanvangstijd,0,2) == substr($aAanvang[$nAfteller],0,2)) {
                                    $nIdnr = "divid" . $nVert;
                        ?>

                        <a href="auditantenkaart-2.php?auditant=<?php echo $aIdAuditant[$nAfteller] ; ?>" target="_blank" title="Klik hier voor de auditantenkaart van <?php echo $aAuditant[$nAfteller] ;?>">
                            <div>
                                <div style="color: brown!important;"><?php echo substr($aAanvang[$nAfteller],0,5) . " - " . substr($aEinde[$nAfteller],0,5) ; ?></div>
                                <div style="color: brown!important;"><?php echo $aAuditant[$nAfteller] . " ->> " . $aUitleg[$nAfteller] ; ?> </div>
                            </div>
                        </a>
                        <?php
                            }
                            $nAfteller++;
                            }

                        ?>

                    </div>
                    <div class="clear"></div>
                    <?php
                        $nVert
++;
                        }

                    ?>

                    <div class="regelhoogte25"></div>
                    
                </div>
                <div class="clear"></div>
            </article>  
        </div>
        <div class="container2">
        
        </div>
    </div>
    <?php include "include/footer.inc.php" ; ?>
</body>


De routine waarbij $nHoogte wordt bepaald gaat fout.

Afbeelding

Toevoeging op 04/03/2014 22:16:47:

In dit voorbeeld moet de hoogte van 10 uur 60px zijn omdat er twee boekingen zijn

Toevoeging op 04/03/2014 22:19:17:

Kijk voor de evt broncode op http://www.podiumspektakel.eu/es-dag.php?datum=2014-03-06#bovenaan
 
PHP hulp

PHP hulp

19/04/2024 16:10:49
 
Ozzie PHP

Ozzie PHP

04/03/2014 22:35:36
Quote Anchor link
Het is maar hoe lastig je het zelf maakt ;)

Maak van dit stukje (hierboven op regel 53)...

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
<?php
if(substr($cAanvangstijd,0,2) == $cTest){
  $nHoogte = ($nArrayTeller * 30) . "px";
}
else {
  $nHoogte = "30px";
}

?>

eens dit:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<?php
if(substr($cAanvangstijd,0,2) == $cTest){
  $nHoogte = ($nArrayTeller * 30) . "px";
  exit('<br><br>HOOGTE IS: ' . $nHoogte);
}
else {
  $nHoogte = "30px";
}

?>

Als je de pagina nu ververst, zie je dan de hoogte in beeld staan?
 
George van Baasbank

George van Baasbank

05/03/2014 15:55:29
Quote Anchor link
Dankzij de vraag over een time-query ben ik er op een eenvoudige wijze uitgekomen:

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
$nVert = 0;
$nVertMax = 24;
$aDatum = array();
$aUitleg = array();
$aAanvang = array();
$aAuditant = array();
$aEinde = array();
$aIdnr = array();
$aHoogte = array();
$nArrayTeller = 0;
$rowUren = mysqli_fetch_array($cResultAfspraken);
                        $aHoogte[] = $rowUren['uur0'];
                        $aHoogte[] = $rowUren['uur1'];
                        $aHoogte[] = $rowUren['uur2'];
                        $aHoogte[] = $rowUren['uur3'];
                        $aHoogte[] = $rowUren['uur4'];
                        $aHoogte[] = $rowUren['uur5'];
                        $aHoogte[] = $rowUren['uur6'];
                        $aHoogte[] = $rowUren['uur7'];
                        $aHoogte[] = $rowUren['uur8'];
                        $aHoogte[] = $rowUren['uur9'];
                        $aHoogte[] = $rowUren['uur10'];
                        $aHoogte[] = $rowUren['uur11'];
                        $aHoogte[] = $rowUren['uur12'];
                        $aHoogte[] = $rowUren['uur13'];
                        $aHoogte[] = $rowUren['uur14'];
                        $aHoogte[] = $rowUren['uur15'];
                        $aHoogte[] = $rowUren['uur16'];
                        $aHoogte[] = $rowUren['uur17'];
                        $aHoogte[] = $rowUren['uur18'];
                        $aHoogte[] = $rowUren['uur19'];
                        $aHoogte[] = $rowUren['uur20'];
                        $aHoogte[] = $rowUren['uur21'];
                        $aHoogte[] = $rowUren['uur22'];
                        $aHoogte[] = $rowUren['uur23'];    

                        while($rowUur    = mysqli_fetch_array($cResultUur)) {
                            $aDatum[]    = $rowUur['datum'];
                            $aUitleg[]   = $rowUur['onderwerp'];
                            $aAanvang[]  = $rowUur['aanvang'];
                            $aEinde[]    = $rowUur['einde'];
                            $aIdnr[]     = $rowUur['id'];
                            $aAuditant[] = $rowUur['voornaam'] . " " . $rowUur['tussenvoeg'] . " " . $rowUur['achternaam'];
                            $aIdAuditant[] = $rowUur['auditant'];
                            $nArrayTeller++;
                        }
                        
                        while($nVert < $nVertMax) {
                            $cAanvangstijd = sprintf('%02d:00:00', $nVert);
                            if(substr($aAanvang[$key],0,2) > 0 AND substr($aAanvang[$key],0,2) < 10) {
                                $cTest = "0" . substr($aAanvang[$key],0,1);
                            } else {
                                $cTest = substr($aAanvang[$key],0,2);
                            }
                            
                            $nHoogte = $aHoogte[$nVert] * 30;
                            if($nHoogte < 30) {
                                $nHoogte = 30;
                            }
                            $nHoogte .= "px";
                    ?>




George

Topic gesloten
 
Ozzie PHP

Ozzie PHP

05/03/2014 16:18:56
Quote Anchor link
Kan aan mij liggen, maar op de een of andere manier ziet die $aHoogte[] array er allesbehalve efficiënt uit. Geen idee wat je wil bereiken, maar ik heb zo'n vermoeden dat er betere manieren bestaan.
 
Jeff NextGDev

Jeff NextGDev

08/03/2014 04:41:34
Quote Anchor link
Ozzie, het is inderdaad moeilijk in te schatten op welke manieren dit beter zou kunnen, maar ik heb inderdaad ook het gevoel dat er dubbel werk wordt verricht.
 



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.