繁体   English   中英

如何使用Codeigniter在for循环中获取每个值

[英]how to get each values in a for loop using codeigniter

` 查看页面,这是获取当前日期和前9个日期的代码。如何将每个日期保存到我的表单中,并将每个选定的日期放到文本框中,//将每个日期放入控制器的form.date_array内部的文本框中

<?  $numItems = count($date_array)-1; 
    echo $numItems; 
    for($i=0;$i<count($date_array);$i++){?>
        <?if($i !=$numItems){?>
        <li>
            <a href="#" class="dp-item"  data-moment="<?echo $date_array[$i]['db_date']?>" title="<?echo $date_array[$i]['title']?>">
            <input   name="income_date" class="form-control" value="<?echo $date_array[$i]['db_date']?>"  type="hidden" />
            <span class="dp-date"><?echo $date_array[$i]['dp_day']?><br><?echo $date_array[$i]['dp_date']?></span>

            <span class="dp-det"><i id="dp-calendar" class="glyphicon glyphicon-calendar">
            </i><?echo $date_array[$i]['day']?><br><?echo $date_array[$i]['date']?></span>
            </a>
        </li>
        <?}else{?>
        <li>
            <a href="#" class="dp-item dp-selected " data-moment="<?echo $date_array[$i]['db_date']?>" title="<?echo $date_array[$i]['title']?>">
            <span class="dp-date" style="display: none;"><?echo $date_array[$i]['dp_day']?><br><?echo $date_array[$i]['dp_date']?></span>
            <span class="dp-det" style="display: block;"><i id="dp-calendar" class="glyphicon glyphicon-calendar">
            </i><?echo $date_array[$i]['day']?><br><?echo $date_array[$i]['date']?></span>
            </a>
        </li>
    <?}}?>

控制者

  //this is the date format 
        public function index()
        {
        $date_array=array();

        $timestamp = time();
        $j=9;
        for ($i = 0 ; $i < 10 ; $i++) {
      //  echo date('Y-m-d', $timestamp) . '<br />';
        //echo date('dS, l F Y', $timestamp) . '<br />';
        $date_array[$j]['db_date']= date('Y-m-d', $timestamp);
        $date_array[$j]['date']= date('dS, F Y', $timestamp);
        $date_array[$j]['day']= date('l', $timestamp);
        $date_array[$j]['title']= date('l, dS F Y', $timestamp);
        $date_array[$j]['dp_day']= date('D', $timestamp);
        $date_array[$j]['dp_date']= date('dS', $timestamp);
        $timestamp -= 24 * 3600;
        $j--;
    } 

脚本

var income_date = document.querySelectorAll('.pagination li a');
alert(income_date);

重写控制器的索引功能并传递数组以在视图页面中显示

    public function index()
    {

        $data=array(); 
           // I declare $data as a new variable 
           // and assign date_array int $data variable then send $data   to the view page

        $timestamp = time();
        $j=9;
        for ($i = 0 ; $i < 10 ; $i++) {
             // echo date('Y-m-d', $timestamp) . '<br />';
            //echo date('dS, l F Y', $timestamp) . '<br />';
            $data['date_array'][$j]['db_date']= date('Y-m-d', $timestamp);
            $data['date_array'][$j]['date']= date('dS, F Y', $timestamp);
            $data['date_array'][$j]['day']= date('l', $timestamp);
            $data['date_array'][$j]['title']= date('l, dS F Y', $timestamp);
            $data['date_array'][$j]['dp_day']= date('D', $timestamp);
            $data['date_array'][$j]['dp_date']= date('dS', $timestamp);
            $timestamp -= 24 * 3600;
            $j--;
    }

    $this->load->view('welcome_message',$data);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM