0

我可以在下拉菜单中选择的数据库中插入正确的生日。当页面在成功更新数据库后重新加载时,仅显示生日下拉菜单的年份部分。为什么会这样?我对所有三个都使用相同的简单逻辑。

 // CONTROLLER

  if($this->form_validation->run() == FALSE )
                    {

                            $data['main_content'] = 'account/edit';
                            $this->load->view('includes/templates/main_page_template', $data);

                        }
                        else
                        {
                            $birthdate = $this->input->post('month'). "-" .$this->input->post('day'). "-" .$this->input->post('year');
                            echo $birthdate;
                            $save_data = array(
                                'relation' => $this->input->post('relation'),
                                'location' => $this->input->post('location'),
                                'birthday' => date('Y-m-d',strtotime($birthdate)),
                                'gender' => $this->input->post('gender'),
                                'mylife' => $this->input->post('mylife'),
                                'occupation' => $this->input->post('occupation'),
                                'hobbies' => $this->input->post('hobbies'),
                                'books' => $this->input->post('books'),
                                'music' => $this->input->post('music'),
                                'movies' => $this->input->post('movies'),
                                'quote' => $this->input->post('quote'),
                                'mycysticlife' => $this->input->post('mycysticlife'),
                                'medicines' => $this->input->post('medicines'),
                                'treatments' => $this->input->post('treatments'),
                                'PFTs:FVC' => $this->input->post('PFTs:FVC'),
                                'FEV1' => $this->input->post('FEV1'),
                                'mutation' => $this->input->post('mutation'),
                                'twitter' => $this->input->post('twitter'),
                                'myspace' => $this->input->post('myspace'),
                                'facebook' => $this->input->post('facebook'),
                                'blogspot' => $this->input->post('blogspot'),
                                'youtube' => $this->input->post('youtube'),
                                'url' => $this->input->post('url'),
                                'city' => $this->input->post('city'),
                                 );


                                    $query = $this->account_model->update_edit($user['id'],$save_data);
                            $data['main_content'] = 'account/profile';
                            $this->load->view('includes/templates/main_page_template', $data);
                        }

                    }
                }

// VIEW

  <?php
                        echo month_dropdown('months', $user['birthday'])." ".day_dropdown('days', $user['birthday'])." ".year_dropdown('year', $user['birthday']);

                    ?>

// FORM HELPER

function month_dropdown($month="month", $top_month='' ) {

   $months = array(
        "choose"=>"Month",
        "Jan"=>"Jan",
        "Feb"=>"Feb",
        "Mar"=>"Mar",
        "Apr"=>"Apr",
        "May"=>"May",
        "Jun"=>"Jun",
        "Jul"=>"Jul",
        "Aug"=>"Aug",
        "Sep"=>"Sep",
        "Oct"=>"Oct",
        "Nov"=>"Nov",
        "Dec"=>"Dec"
  );

  $html = "<select name='{$month}'>";

  foreach($months as $key => $month){

      $selected = "";
      //this will match for selected value and set the selected attribute
      if( $key == $top_month ) {
          $selected = "selected='selected'";
      }
      $html .="<option value='{$key}' $selected>{$month}</option>";
  }
  $html .="</select>";
  return $html;

}

function day_dropdown($day="day", $top_days="") {
   $days = array(
        "choose"=>"Day",
        "01"=>"01",
        "02"=>"02",
        "03"=>"03",
        "04"=>"04",
        "05"=>"05",
        "06"=>"06",
        "07"=>"07",
        "08"=>"08",
        "09"=>"09",
        "10"=>"10",
        "11"=>"11",
        "12"=>"12",
        "13"=>"13",
        "14"=>"14",
        "15"=>"15",
        "16"=>"16",
        "17"=>"17",
        "18"=>"18",
        "19"=>"19",
        "20"=>"20",
        "21"=>"21",
        "22"=>"22",
        "23"=>"23",
        "24"=>"24",
        "25"=>"25",
        "26"=>"26",
        "27"=>"27",
        "28"=>"28",
        "29"=>"29",
        "30"=>"30",
        "31"=>"31"
   );

   $html = "<select name='{$day}'>";

   foreach($days as $key => $day){
      $selected = "";
      if( $key == $top_days ) {
          $selected = "selected='selected'";
      }

      $html .="<option value='{$key}' $selected >{$day}</option>";
   }
   $html .="</select>";
   return $html;

}

function year_dropdown($year="year", $top_years='') {
   $years = array(
        "choose"=>"Year",
        "1997"=>"1997",
        "1996"=>"1996",
        "1995"=>"1995",
        "1994"=>"1994",
        "1993"=>"1993",
        "1992"=>"1992",
        "1991"=>"1991",
        "1990"=>"1990",
        "1989"=>"1989",
        "1988"=>"1988",
        "1987"=>"1987",
        "1986"=>"1986",
        "1985"=>"1985",
        "1984"=>"1984",
        "1983"=>"1983",
        "1982"=>"1982",
        "1981"=>"1981",
        "1980"=>"1980",
        "1979"=>"1979",
        "1978"=>"1978",
        "1977"=>"1977",
        "1976"=>"1976",
        "1975"=>"1975",
        "1974"=>"1974",
        "1973"=>"1973",
        "1972"=>"1972",
        "1971"=>"1971",
        "1970"=>"1970",
        "1969"=>"1969",
        "1968"=>"1968",
        "1967"=>"1967",
        "1966"=>"1966",
        "1965"=>"1965",
        "1964"=>"1964",
        "1963"=>"1963",
        "1962"=>"1962",
        "1961"=>"1961",
        "1960"=>"1960",
        "1959"=>"1959",
        "1959"=>"1959",
        "1958"=>"1958",
        "1957"=>"1957",
        "1956"=>"1956",
        "1955"=>"1955",
        "1954"=>"1954",
        "1953"=>"1953",
        "1953"=>"1953",
        "1952"=>"1952",
        "1951"=>"1951",
        "1950"=>"1950",
        "1949"=>"1949",
        "1948"=>"1948",
        "1947"=>"1947",
        "1946"=>"1946",
        "1945"=>"1945",
        "1944"=>"1944",
        "1943"=>"1943",
        "1942"=>"1942",
        "1941"=>"1941",
        "1940"=>"1940",
        "1939"=>"1939",
        "1938"=>"1938",
        "1937"=>"1937",
        "1936"=>"1936",
        "1935"=>"1935",
        "1934"=>"1934",
        "1933"=>"1933",
        "1932"=>"1932",
        "1931"=>"1931",
        "1930"=>"1930"

   );

   $html = "<select name='{$year}'>";

   foreach($years as $key => $year){

      $selected = "";
      if( $key == $top_years ) {
          $selected = "selected='selected'";
      }

     $html .="<option value='{$key}' $selected >{$year}</option>";
   }
   $html .="</select>";
   return $html;

 }


// MODEL

  public function update_edit($id,$data)
    {
        $this->db->where('id', $id);
        $this->db->update('users', $data);

    }
}


thanks in advance
4

1 回答 1

1

只是仔细看了一下代码,我看到了这一行,并假设它是给你带来问题的那一行?

echo month_dropdown('months', $user['birthday'])." ".day_dropdown('days', $user['birthday'])." ".year_dropdown('year', $user['birthday']);

该变量应该以您保存的格式返回日期,因此对我来说它将返回 09-12-1967,这可能不是您的下拉菜单的合法值。您可以将其分解,然后像这样填充下拉列表:

$birthdate = explode('-',$user['birthday']);
 echo month_dropdown('months', $birthdate[0])." ".day_dropdown('days', $birthdate[1])." ".year_dropdown('year', $birthdate[2]);

那应该工作

于 2013-01-24T00:14:30.637 回答