Datumformat / Vergleich / Optionsfeld

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Datumformat / Vergleich / Optionsfeld

    moinsken,
    habe folgendes Problem:
    Ich will ein Optionsfeld erzeugen, das mir den heutigen Tag als Voreinstellung (<option selected >) anzeigt:
    PHP-Code:
    function optionFieldDatum($format){   
        
    $optionField '';
        switch (
    $format){
          case 
    'tag' :
                for (
    $i 1$i <= 31$i++){
                  if(
    $i <10){ $target "0".$i; }else {  $target $i; }
                  if(
    $target == date("d"time())){
                     
    $optionField .= '<option selected value="'.$target.'">'.$target.'</option>';
                  }else{  
                     
    $optionField .= '<option value="'.$target.'">'.$target.'</option>';
                  }
                }
                return 
    $optionField;
           case 
    'monat' :
                for (
    $i 1$i <= 12$i++){
                  if(
    $i <10){ $target "0".$i; }else {  $target $i; }       
                  if(
    $target == date("m"time())){
                     
    $optionField .= '<option selected value="'.$target.'">'.$target.'</option>';
                  }else{  
                     
    $optionField .= '<option value="'.$target.'">'.$target.'</option>';
                  }
                }             
               return 
    $optionField
           case 
    'jahr' :
                
    $start date("Y"time()) - 5;
                
    $end date("Y"time()) + 5;
                for (
    $i $start$i <= $end$i++){
                    
    $target $i;             
                    if(
    $target == strftime("%Y"time())){
                       
    $optionField .= '<option selected value="'.$target.'">'.$target.'</option>';
                    }else{  
                       
    $optionField .= '<option value="'.$target.'">'.$target.'</option>';
                    }
                }       
                return 
    $optionField;  
          }

    Mit $format gebe ich an ob mir ein Optionsfeld für Tage, Monate oder Jahr zurückgegeben wird.
    Nur klappt der Vergleich von Zähler ($target) mit dem Aktuellen Datum (date("Y", time()) oder strftime("%Y", time())) nicht...
    Kann mich einer aufklären was ich falsch mache?
    "I don't want to belong to any club that would accept me as a member."

    Groucho Marx

  • #2
    Testausgaben gemacht? Was steht in $target wenn es nicht klappt? Und was sollte drin stehen?
    Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

    [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
    Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

    Kommentar


    • #3
      Hmmm, hatte ich eigentlich gemacht, jetzt schreibt mir das script im Treffer fall
      <option selected value="04">04</option>
      in den Quellcode,
      Firebug zeigt mir
      <option selected="" value="04">04</option>
      an
      "I don't want to belong to any club that would accept me as a member."

      Groucho Marx

      Kommentar


      • #4
        Mich würde es eigentlich mehr interessieren was Testausgaben von $target und der entsprechenden Time Fkt ergeben...
        Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

        [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
        Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

        Kommentar


        • #5
          Sorry...
          echo "t: ".$target."; date: ".date("d", time())."<br>";
          gibt mir:
          t: 01; date: 04
          t: 02; date: 04
          t: 03; date: 04
          t: 04; date: 04
          t: 05; date: 04
          t: 06; date: 04
          t: 07; date: 04
          t: 08; date: 04
          t: 09; date: 04
          t: 10; date: 04
          t: 11; date: 04
          t: 12; date: 04
          etc.
          Bin verwirrt weil beim 4ten option feld ja richtig:
          <option selected value="04">04</option>
          einegsetzt wird, aber der Eintrag wird nicht vorselektiert....
          "I don't want to belong to any club that would accept me as a member."

          Groucho Marx

          Kommentar


          • #6
            Falls XHTML wäre selected="selected" eher angebracht. Und das ganze steht schon zwischen <select> und </select>
            Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

            [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
            Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

            Kommentar


            • #7
              @jahlives: hast recht, habe ich auch gerade gemerkt - hatte ne alte Funktion von mir genommen...
              aber *Seufz* Opera & IE zeigen es mir richtig an.... Firefox aba nich ???
              "I don't want to belong to any club that would accept me as a member."

              Groucho Marx

              Kommentar

              Lädt...
              X