duancunsu9209 2015-06-04 04:50
浏览 43
已采纳

如何使用codeigniter获取for循环中的每个值

`view page this is the code for getting the current date and previous 9 dates.how to get each date to my form and put each selected date to a textbox //get each date into a textbox inside the form.date_array from the controller

<?  $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>
    <?}}?>

controller

  //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--;
    } 

script

var income_date = document.querySelectorAll('.pagination li a');
alert(income_date);
  • 写回答

1条回答 默认 最新

  • drlnwji79147769 2015-06-04 05:50
    关注

    Rewrite the index funtion of your controller & pass the array to show in view page

        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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘