Gegevens uit database halen lukt niet

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Lars Mennen

Lars Mennen

29/09/2009 21:29:00
Quote Anchor link
Hallo,

Ik wil bij iedere pagina de content uit een database halen.
Toch laat hij bij iedere pagina de content van "Home" (de eerste pagina) zien.

Dit is het stuk PHP:
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
<?php
                        if (isset($_GET['p']) == 'Home'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Home' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        elseif (isset($_GET['p']) == 'Agenda'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Agenda' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        elseif (isset($_GET['p']) == 'Biografie'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Biografie' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        elseif (isset($_GET['p']) == 'Fotos'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Fotos' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        elseif (isset($_GET['p']) == 'Repertoire'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Repertoire' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        elseif (isset($_GET['p']) == 'Gastenboek'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Gastenboek' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        elseif (isset($_GET['p']) == 'Links'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Links' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        elseif (isset($_GET['p']) == 'Contact'){
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Contact' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                        else {
                            $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Home' AND post_type='page'");
                            $tekst = mysql_fetch_array($output);
                        
                            echo $tekst['post_content'];
                            }

                            
                    ?>


En dit het menu:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
                <ul class="Uitgeklapt">
                
                    <li><a href="#" class="Inklappen"><img id="PijlRechts" src="images/PijlRechts.png" alt="Pijl naar rechts" /></a></li>
                    <li class="cufon"><a href="index.php?p=Home">Home</a></li>
                    <li class="cufon"><a href="index.php?p=Agenda">Agenda</a></li>
                    <li class="cufon"><a href="index.php?p=Biografie">Biografie</a></li>
                    <li class="cufon"><a href="index.php?p=Fotos">Fotos</a></li>
                    <li class="cufon"><a href="index.php?p=Repertoire">Repertoire</a></li>
                    <li class="cufon"><a href="index.php?p=Gastenboek">Gastenboek</a></li>
                    <li class="cufon"><a href="index.php?p=Links">Links</a></li>
                    <li class="cufon"><a href="index.php?p=Contact">Contact</a></li>
                </ul>


Ziet iemand het probleem of weet iemand de oplossing?
Bij voorbaat dank!

Larsm.
 
PHP hulp

PHP hulp

21/05/2024 06:54:49
 
- SanThe -

- SanThe -

29/09/2009 22:09:00
Quote Anchor link
if (isset($_GET['p']) == 'Home'){

Hier staat eigenlijk dit al naar gelang of de GET is geset.

if(true == 'home'){ of if(false == 'home'){


Je bedoelt waarschijnlijk dit:
if (isset($_GET['p']) and $_GET['p'] == 'Home'){
 
Yearupie Achternaamloos

Yearupie Achternaamloos

29/09/2009 22:19:00
Quote Anchor link
Het is onzin om 10x te kijken of $_GET['p'] bestaat...

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
<?php
if (isset($_GET['p'])){
    if ($_GET['p'] == 'Home'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Home' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    elseif ($_GET['p'] == 'Agenda'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Agenda' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    elseif ($_GET['p'] == 'Biografie'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Biografie' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    elseif ($_GET['p'] == 'Fotos'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Fotos' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    elseif ($_GET['p'] == 'Repertoire'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Repertoire' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    elseif ($_GET['p'] == 'Gastenboek'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Gastenboek' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    elseif ($_GET['p'] == 'Links'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Links' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    elseif ($_GET['p'] == 'Contact'){
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Contact' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }

    else {
        $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Home' AND post_type='page'");
        $tekst = mysql_fetch_array($output);
        
        echo $tekst['post_content'];
    }
}

else {
    $output = mysql_query("SELECT * FROM music_posts WHERE post_title='Home' AND post_type='page'");
    $tekst = mysql_fetch_array($output);
    
    echo $tekst['post_content'];
}

?>
Gewijzigd op 01/01/1970 01:00:00 door Yearupie Achternaamloos
 
- SanThe -

- SanThe -

29/09/2009 22:30:00
Quote Anchor link
Een switch() is nog netter. En dan alleen de sql in een variabele zetten. Na de switch pas de query uitvoeren inclusief foutafhandeling en dan als laatste de echo.
 
Jan Willem van der Veer

Jan Willem van der Veer

30/09/2009 09:09:00
Quote Anchor link
Waarom niet gewoon zo:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
<?php
$aPossiblePages
= Array('Links', 'Biografie', 'Agenda', 'Fotos', 'Repetoire', 'Gastenboek', 'Contact');
$sPage = 'Home';

if(isset($_GET['p']) && in_array($_GET['p'], $aPossiblePages)) $sPage = $_GET['p'];

if(($rMusicPost = mysql_query('SELECT * FROM music_posts WHERE (post_title=\''.$sPage.'\') AND (post_type=\'page\')')) && (mysql_num_rows($rMusicPost) == 1)){
  $aTekst = mysql_fetch_array($rMusicPost);
  echo $aTekst['post_content'];
}

?>


Een heel stuk korter... Daarnaast is die switch ook gewoon geen goed idee..
 



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.