Kleine Vragen Topic #1

Gestart doorLennard4.284 reacties15.585 weergaven

4.285 berichten · pagina 260 van 286

Berichten
6.201
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat is een goede manier om iemands leeftijd te berekenen aan de hand van een geboortedatum die in de database staat?

Op google krijg ik enkel sites uit 2006 gevonden, en ziet er erg omslachtig uit.
0
Berichten
6.201
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
http://ma.tt/2003/12/calculate-age-in-mysql/ biggrin
zelf doe ik hem in PHP overigens
Hmm..

Heb nu dit:

$result = mysql_query("SELECT *, CURDATE(), (YEAR(CURDATE())-YEAR(geb_datum)) - RIGHT(CURDATE(),5) < RIGHT(geb_datum,5) AS leeftijd FROM leden ORDER BY naam ASC");
                while($list = mysql_fetch_assoc($result)){


en dan wil ik via $list[leeftijd]; de leeftijd weergeven, maar dan krijg ik helaas overal 0 te zien sadley
Ik weet overigens ook niet wat die ,5 doet, maar dat heb ik gekopieerd van http://dev.mysql.com/doc/refman/5.0/en//date-calculations.html
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Je hebt wel een veld met DATETIME-type?
0
Berichten
6.201
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Je hebt wel een veld met DATETIME-type?
Hmm.. Hij is date, en ze staan er zo in.. 1990-02-21
Is dit makkelijk om te zetten?
0
Lennard

Lid · Topicstarter

Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
date is ook goed, maar zeker weten dat het date is en geen text of varchar ofzo?

toevoeging op 15 maart 2013, 11:59:55:
je miste haakjes yummie
0
Berichten
6.201
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
date is ook goed, maar zeker weten dat het date is en geen text of varchar ofzo?
toevoeging op 15 maart 2013, 11:59:55:
je miste haakjes yummie
Thanks! Ik faal emo
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Sevvlor schreef:
Weet iemand hoe je "Routines, Events en Triggers" uit zet in phpMyAdmin? Ik heb overal gezocht maar ik kan het niet vinden.
Iemand die dit weet?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Ik ben nu dus voor het eerst aan het uitlijnen en mijn vraag is, is het zo goed uitgelijnd?

<a href="?aantal=10">10</a> | <a href="?aantal=50">50</a> | <a href="?aantal=100">100</a> | <a href="?aantal=500">500</a> | <a href="?aantal=all">Alles</a>
<table border="1">
  <tr>
    <th>ID</th>
    <th>Punten</th>
    <th>Priveberichten</th>
    <th>Forum berichten</th>
    <th>Laatst online</th>
    <th>Datum</th>
  </tr>
[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700]);[/COLOR] 
    [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700]);[/COLOR] 

    [COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]];[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]10[/COLOR][COLOR= #007700]) {[/COLOR]
              [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 10"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]50[/COLOR][COLOR= #007700]) {[/COLOR]
              [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 50"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]100[/COLOR][COLOR= #007700]) {[/COLOR]
              [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 100"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]500[/COLOR][COLOR= #007700]) {[/COLOR]
             [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 500"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] all[COLOR= #007700]) {[/COLOR]
             [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC"[/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]Aantal niet gevonden.[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/exit"]exit[/URL][COLOR= #007700]();
        }[/COLOR]
    [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$aLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$qLid[/COLOR][COLOR= #007700])) 
    {[/COLOR]
?>
<tr>
    <td><?=$aLid[id]?></td>
    <td><?=$aLid[punten]?></td>
    <td><?=$aLid[berichten]?></td>
    <td><?=$aLid[posts]?></td>
    <td><?=$aLid[online]?></td>
    <td><?=$aLid[datum]?></td>
</tr>
[COLOR= #0000BB]<?php[/COLOR]
    [COLOR= #007700]}[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</table>[/COLOR][COLOR= #007700];[/COLOR]
?>
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Het ziet er leesbaar uit, maar waarom vijf queries welke je per voorwaarde uitvoert? Je kan ook het getal opslaan, en na afloop deze in de query verwerken. Zo houd je je code makkelijk onderhoudbaar als je je query aan moet passen.

Ook die exit() is not done. Een script MOET NIET dood gaan.
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Gebruik ipv
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Jellesch schreef:
Ik ben nu dus voor het eerst aan het uitlijnen en mijn vraag is, is het zo goed uitgelijnd?
<a href="?aantal=10">10</a> | <a href="?aantal=50">50</a> | <a href="?aantal=100">100</a> | <a href="?aantal=500">500</a> | <a href="?aantal=all">Alles</a>
<table border="1">
  <tr>
    <th>ID</th>
    <th>Punten</th>
    <th>Priveberichten</th>
    <th>Forum berichten</th>
    <th>Laatst online</th>
    <th>Datum</th>
  </tr>
[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700]);[/COLOR] 
    [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"xxxxx"[/COLOR][COLOR= #007700]);[/COLOR] 

    [COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]];[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]10[/COLOR][COLOR= #007700]) {[/COLOR]
              [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 10"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]50[/COLOR][COLOR= #007700]) {[/COLOR]
              [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 50"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]100[/COLOR][COLOR= #007700]) {[/COLOR]
              [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 100"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]500[/COLOR][COLOR= #007700]) {[/COLOR]
             [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC LIMIT 500"[/COLOR][COLOR= #007700]); 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR] [COLOR= #007700]==[/COLOR] all[COLOR= #007700]) {[/COLOR]
             [COLOR= #0000BB]$qLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM jellesch ORDER BY id DESC"[/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]Aantal niet gevonden.[/COLOR][COLOR= #007700];[/COLOR]
            [URL="http://www.php.net/exit"]exit[/URL][COLOR= #007700]();
        }[/COLOR]
    [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$aLid[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$qLid[/COLOR][COLOR= #007700])) 
    {[/COLOR]
?>
<tr>
    <td><?=$aLid[id]?></td>
    <td><?=$aLid[punten]?></td>
    <td><?=$aLid[berichten]?></td>
    <td><?=$aLid[posts]?></td>
    <td><?=$aLid[online]?></td>
    <td><?=$aLid[datum]?></td>
</tr>
[COLOR= #0000BB]<?php[/COLOR]
    [COLOR= #007700]}[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</table>[/COLOR][COLOR= #007700];[/COLOR]
?>


Binnnen je if-else constructie heb je tabbing van 6 spaties. De standaard is 4 spaties.
Verder is het een kwestie van smaak, maar is het voor mij gebruikelijk om met de Zend Coding Standards te werken.
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sanderc schreef:
Gebruik ipv
just dont...
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
@rik: Overigens houd Zend zich nu, sinds versie 2 van het framework, aan de PSR-0 standards.
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