2010-07-20 58 views
-1
中給出的字符串

它的警告:date()期望參數2很長,在

$ birthDay = date(「d」,$ alder); $ birthYear = date(「Y」,$ alder);

我不知道它是什麼

這裏是我的代碼

 //Dag 
      $maxDays = 31; 
      $birthDay = date("d", $alder); 
      echo '<select name="day">'; 
      echo '<option value="">Dag</option>'; 
      for($i=1; $i<=$maxDays; $i++) 
      { 
      echo '<option '; if($birthDay == $i){ echo 'selected="selected"'; } echo ' value="'.$i.'">'.$i.'</option>'; 
      } 
      echo '</select>'; 

     //Måned 
      echo '<select name="month">'; 
      $birthMonth = date("m", $alder); 
      $aManeder = 12; 
      echo '<option value="">Måned</option>'; 
      for($i = 1; $i <= $aManeder; $i++) 
      { 
      echo '<option '; if($birthMonth == $i) { echo 'selected="selected"'; } echo ' value="'.$i.'">'.$ManderArray[$i].'</option>'; 
      } 
      echo '</select>'; 


     //År 
      $startYear = date("Y"); 
      $endYear = $startYear - 30; 
      $birthYear = date("Y", $alder); 
      echo '<select name="year">'; 
      echo '<option value="">år</option>'; 
      while($endYear <= $startYear) 
      { 
      echo '<option '; if($birthYear == $endYear) { echo 'selected="selected"'; } echo ' value="'.$endYear.'">'.$endYear.'</option>'; 
      $endYear++; 
      } 
      echo '</select>'; 
+0

什麼樣的價值有$榿木? – Grumpy 2010-07-20 20:53:39

+0

[Warning:mysql_fetch_ *期望參數1是資源,布爾給定錯誤]的可能重複(http://stackoverflow.com/questions/11674312/warning-mysql-fetch-expects-parameter-1-to-be-resource -boolean-given-error) – j0k 2012-07-29 07:20:19

回答

0

錯誤消息說,這一切:參數2($榿木)沒有一個有效的數值。插入以下行錯誤行前面,並追溯$榿木的當前值的由來:

var_dump($alder); 

您可以用0或microtime中(真)初始化$榿木,使日期()獲取一個有效的參數。但是,如果您將其設置爲空字符串(''),您將始終收到上述錯誤消息。

+0

然後用戶創建一個新用戶$ al木是空的,所以它不能是emty? – Simon 2010-07-20 22:16:17

+0

'if(!is_int($ alder)){$ alder = 0; }' – JLRishe 2013-01-14 08:35:25

0

在您的失敗聲明之前試試這個:

$ alder =(int)$ alder;

0

date() function需要一個unix時間戳...我似乎是通過它作爲一個字符串的日期。

例如2014-01-10

你應該使用:

$birthMonth = date("m", strtotime($alder)); 
相關問題