Problem mit Php ausgabe

Dieses Thema im Forum "Webentwicklung" wurde erstellt von Mr. Brown, 11. Juni 2006 .

Schlagworte:
Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 11. Juni 2006
    Hi jungs, ich muss als klausur ersatzleistung ein programm erstellen wo man eingeben muss wann man geburtstag hat und es dann ausrechnet wie alt man momentan ist. soweit so gut. leider will er mit einfach keine ausgabe geben.
    Könnt ihr mal nachschauen? ich raffs nicht.


    10ner is gewiss


    ________________________________________________
    Code:
    <?php
    
     
    $day = date("j");
    $month = date("m"); 
    $year = date("Y"); 
     
    $age = $year-$birthyear; 
     
    if($month < $birthmonth) 
     { 
     $alter = $age-1; 
     } 
     
    elseif($month > $birthmonth) 
     {
     $alter = $age; 
     } 
     
    elseif($month == $birthmonth) 
     { 
     if($day < $birthday) 
     { 
     $alter = $age-1; 
     } 
     elseif($day > $birthday) 
     { 
     $alter = $age; 
     } 
     elseif($day == $birthday) 
     {
     $alter = $age; 
     } 
     } 
     
    if(!$birthday || !$birthmonth || !$birthyear) 
     { 
    echo "<form method=\"post\"> 
    <select name=\"birthday\"> 
    <option value=\"\">---</option>\n"; 
     
    for($i=1; $i <= 31; $i++) 
    { 
    echo "<option value=\"$i\""; if($i == "$birthday") { echo " selected"; } echo ">$i</option>\n"; 
    } 
     
    echo "</select> 
    <select name=\"birthmonth\"> 
    <option value=\"\">---</option>\n"; 
    
    for($i=1; $i <= 12; $i++) 
    { 
    echo "<option value=\"$i\""; if($i == "$birthmonth") { echo " selected"; } echo ">$i</option>\n"; 
    } 
     
    echo "</select> 
    <select name=\"birthyear\"> 
    <option value=\"\">------</option>\n"; 
     
    for($i=1900; $i <= 2005; $i++)
    { 
    echo "<option value=\"$i\""; if($i == "$birthyear") { echo " selected"; } echo ">$i</option>\n"; 
    } 
     
    echo "</select> 
    <br> 
    <br> 
    <input type=\"submit\" value=\"Alter ausrechnen\"> 
    </form>"; 
     } 
    else 
     {
    echo "Geburtstag: 
    <br> 
    $birthday.$birthmonth.$birthyear
    <br> 
    <br> 
    Alter: 
    <br> 
    $alter"; 
     }
    ?>
    
     
  2. 11. Juni 2006
    wo ist die ausgabe?
     
  3. 11. Juni 2006
    -move-
     
  4. 11. Juni 2006
    hier

    echo "Geburtstag:
    <br>
    $birthday.$birthmonth.$birthyear
    <br>
    <br>
    Alter:
    <br>
    $alter";
    }
    ?>
     
  5. 11. Juni 2006
    Müssen die Variablennamen nicht in ner Klammer stehen: Sprich echo($1,$2...); ?
     
  6. 11. Juni 2006
    Folgendes müsste das Problem beheben:

    <?

    echo "Geburtstag <br>" . $birthday.$birthmonth.$birthyear . "<br><br>Alter: " . $alter;

    ?>
     
  7. 11. Juni 2006
    Das geht vieeel einfacher..

    also:


    time(); ist der aktuelle Timestamp..

    mktime(...);
    damit erstellst du dir nen Timestamp von dem eingegebenen Geburtsdatum..

    $Alter_Time = time() - mktime(..);

    und dann rechnest du halt nen bisschen mit den Sekunden - fertig..^^
     
  8. 13. Juni 2006
    geht aber nur solange das geburtsdatum nicht vorm 1.1.1970 liegt.
     
  9. 14. Juni 2006
    moin,
    ich habe deinen Code mal ein wenig abgeändert. Es ist zwar nicht der schönste Programmierstil, sollte dir aber helfen dein Problem zu erkennen, da der folgende Code funktioniert:

    Code:
    <?php
    
    if($_POST)
     {
    
    $birthday = $_POST['birthday'];
    $birthmonth = $_POST['birthmonth'];
    $birthyear = $_POST['birthyear'];
    
    $day = date("j");
    $month = date("m"); 
    $year = date("Y"); 
     
    $age = $year-$birthyear; 
     
    if($month < $birthmonth) 
     { 
     $alter = $age-1; 
     } 
     
    elseif($month > $birthmonth) 
     {
     $alter = $age; 
     } 
     
    elseif($month == $birthmonth) 
     { 
     if($day < $birthday) 
     { 
     $alter = $age-1; 
     } 
     elseif($day > $birthday) 
     { 
     $alter = $age; 
     } 
     elseif($day == $birthday) 
     {
     $alter = $age; 
     } 
     } 
     
    echo "Geburtstag: 
    <br> 
    echo $birthday.$birthmonth.$birthyear
    <br> 
    <br> 
    Alter: 
    <br> 
    $alter"; 
    }
    else //!$birthday || !$birthmonth || !$birthyear) 
     { 
    echo "<form method=\"post\"> 
    <select name=\"birthday\"> 
    <option value=\"\">---</option>\n"; 
     
    for($i=1; $i <= 31; $i++) 
    { 
    echo "<option value=\"$i\""; if($i == "$birthday") { echo " selected"; } echo ">$i</option>\n"; 
    } 
     
    echo "</select> 
    <select name=\"birthmonth\"> 
    <option value=\"\">---</option>\n"; 
    
    for($i=1; $i <= 12; $i++) 
    { 
    echo "<option value=\"$i\""; if($i == "$birthmonth") { echo " selected"; } echo ">$i</option>\n"; 
    } 
     
    echo "</select> 
    <select name=\"birthyear\"> 
    <option value=\"\">------</option>\n"; 
     
    for($i=1900; $i <= 2005; $i++)
    { 
    echo "<option value=\"$i\""; if($i == "$birthyear") { echo " selected"; } echo ">$i</option>\n"; 
    } 
     
    echo "</select> 
    <br> 
    <br> 
    <input type=\"submit\" value=\"Alter ausrechnen\"> 
    </form>"; 
     } 
    ?>
    
    Gruß Resus
     
  10. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.