dozoqn3347 2016-08-15 03:18
浏览 26
已采纳

为'year'列创建下拉列表而不显示0

I want to show the year list without 0, I got 2 yearlist which is 2016 and 2017 in table called invoice_template, so I should get yearlist for 2016 and 2017. May I know any idea to solve this issue? Below is the code and image:

    public function getYear(){   

        $year = Yii::app()->user->getState('start_year');
        $queryString = "select distinct year from invoice_template where year =:year ORDER BY year ASC";
        $params[':year'] = $year;

        $command = Yii::app()->db->createCommand($queryString);
        $command->params = $params;            
        $yearList = $command->queryAll();

        return $yearList;

     }

Before the dropdownlist and After click the dropdownlist

  • 写回答

1条回答 默认 最新

  • drmqzb5063 2016-08-15 03:49
    关注

    As i said in the comments - the queryAll() is the culprit - it returns a nested array: try this - which will return only the results from the queried row

    $yearList = $command->queryRow();
    

    If you want to keep the array - you will need to a a foreach() or other method of traversing the array to display each value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo