Bull Stark Bull Stark - 5 months ago 13
PHP Question

Create dropdownlist for 'year' column without showing 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


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.