Re: Outputting a 2 digit number < 10

From: Date: Mon, 29 Jan 2001 00:17:34 +0000
Subject: Re: Outputting a 2 digit number < 10
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37128@lists.php.net to get a copy of this message
I normally solve this problem by doing a "< 10" test, on the assumption it is quicker. Something like for ($i=00;$i<$daysinmonth;$i++) {
      $str_i= (string) $i;
      if ( $i < 10 ) { $str_i = "0$str_i"; }
      if ($i == $day)
      {
         echo("<option SELECTED value=\"$str_i\">$str_i</option>\n");
      }
      else
      {
         echo("<option value=\"$str_i\">$str_i</option>\n");
      }
}
<? echo"<select name=\"form_date_day\">";
              $day = (date ("d"));
              $daysinmonth = (date("t"));
        for ($i=00;$i<$daysinmonth;$i++){
          if ($i == $day) {
           echo("<option SELECTED value=\"$i\">$i</option>\n");
          } else {
            echo("<option value=\"$i\">$i</option>\n");
           }
         }
         echo"</select>"
?>
At 01:07 26/01/2001 +0800, you wrote:
I need to enable a user to insert an 'NEWS' item into a mySQL table one of the definable limits for the user is to be the date that the news is to be displayed. Currently the collum is in a 'date' format and should be stored in a YYYYMMDD - being Australian we are used to the exact reverse of that so I though it best to produce a series of three select options in html and then joing the values before inserting them $form_date = $form_date_Year . $form_date_month . $form_date_day; CRUX: the looping format I'm using to make the options needs to output a 2 digit number as a single digit like 1 as compared to 01 will invalidate the date Sample of a loop I use to output an option <? echo"<select name=\"form_date_day\">";
              $day = (date ("d"));
              $daysinmonth = (date("t"));
        for ($i=00;$i<$daysinmonth;$i++){
          if ($i == $day) {
           echo("<option SELECTED value=\"$i\">$i</option>\n");
          } else {
            echo("<option value=\"$i\">$i</option>\n");
           }
         }
         echo"</select>"
?> Any help will be apreciated Jamie
------------------------- Brian White Step Two Designs Pty Ltd - SGML, XML & HTML Consultancy Phone: +612-93197901 Web: http://www.steptwo.com.au/ Email: bwhite@steptwo.com.au

« previous php.general (#37128) next »