OOP PHP vraagje

Gestart doorJosnl10 reacties20 weergaven

11 berichten · pagina 1 van 1

Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Ik heb net de volgende code geschreven in php, maar weet niet of dit kan wat ik nu wil:

[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/class"]class[/URL] userName[COLOR= #007700]{[/COLOR]
    
    [COLOR= #0000BB]$rQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT rechten FROM gebruikers WHERE id="[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user_id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$aRechten[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rQuery[/COLOR][COLOR= #007700]))[/COLOR]
        
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$showRechten[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$aRechten[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]rechten[/COLOR][COLOR= #007700]];[/COLOR]
        
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$showRechten[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/COLOR]
                
                [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Admin[/COLOR][COLOR= #007700];
                
            }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
                
                [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Lid[/COLOR][COLOR= #007700];
                
            }
            
        }[/COLOR]
        
[COLOR= #0000BB]$echoUserName[/COLOR] [COLOR= #007700]= new[/COLOR] userName[COLOR= #007700];[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$echoUserName[/COLOR][COLOR= #007700];[/COLOR]        

?>


Ik wil namelijk dat de rang van de user word getoond.

Ik hoop dat iemand mij kan helpen/verbeteren,

gr. Jos
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het kan wel, maar niet op deze manier. Het is meer een function wat je hierboven hebt..
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zou je kunnen helpen met hoe het dan wel moet?bloos
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Kan je al scripten in functies?
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Niet echt, ben ik nu aan het leren.yummie
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zou daar mee beginnen, leer eer goed werken met functies, en ga daarna OOP erbij doen, dan is het een makkie!
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Maar kan je niet vertellen hoe ik deze code kan verbeteren dan?
0
Berichten
545
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/class"]class[/URL] userName[COLOR= #007700]{
    
    function[/COLOR] userName[COLOR= #007700]() {[/COLOR]
    [COLOR= #0000BB]$rQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT rechten FROM gebruikers WHERE id="[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user_id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$aRechten[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rQuery[/COLOR][COLOR= #007700]))[/COLOR]
        
        [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$showRechten[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$aRechten[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]rechten[/COLOR][COLOR= #007700]];[/COLOR]
        
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$showRechten[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/COLOR]
                
                [COLOR= #0000BB]$recht[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Admin[/COLOR][COLOR= #007700];
                
            }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
                
                [COLOR= #0000BB]$recht[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Lid[/COLOR][COLOR= #007700];
                
            }[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$recht[/COLOR][COLOR= #007700];
}
            
        }[/COLOR]
        
[COLOR= #0000BB]$echoUserName[/COLOR] [COLOR= #007700]= new[/COLOR] userName[COLOR= #007700];[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$echoUserName[/COLOR][COLOR= #007700]->[/COLOR]userName[COLOR= #007700]();[/COLOR]        

?>
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/class"]class[/URL] userName
[COLOR= #007700]{
    
    function[/COLOR] userName[COLOR= #007700]()
    {[/COLOR]
        
        [COLOR= #0000BB]$rQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT rechten FROM gebruikers WHERE id="[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user_id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$aRechten[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$rQuery[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$showRechten[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$aRechten[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]rechten[/COLOR][COLOR= #007700]];[/COLOR]
        
        [COLOR= #0000BB]$recht[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$showRechten[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #DD0000]Admin[/COLOR] [COLOR= #007700]:[/COLOR] [COLOR= #DD0000]Lid[/COLOR][COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$recht[/COLOR][COLOR= #007700];
        
    }
    
}[/COLOR]

[COLOR= #0000BB]$echoUserName[/COLOR] [COLOR= #007700]= new[/COLOR] userName[COLOR= #007700];[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$echoUserName[/COLOR][COLOR= #007700]->[/COLOR]userName[COLOR= #007700]();[/COLOR]
?>
0
Berichten
545
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt voor het verbeteren..
0
Josnl

Lid · Topicstarter

Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt Luuk en Maurice, hier leer ik nog wat van!biggrin
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren