PHP MySQL: Select column with title like year -


my table ('contas') has columns correspond years (2014, 2015, etc...) among other columns, like:

id   | name   | notes   |   2014   | 2015   | 2016 1    | abc    | whatever|   5.25   |  8.50  | 9.50 

i want use php select column corresponds current year table.

i have:

$ano=date('y'); $ano=(string)$ano;  $sql = "select `id`, `name`, `notes`, $ano 'saldo' `contas` ...";   $result = $pdo->query($sql); $rows = $result->fetchall(pdo::fetch_assoc); 

in column 'saldo' i'm getting 2014 every row, instead of values of table.

i tried inserting $ano single , double quotes in query, didn't work.

escape column name..

$sql = "select `id`, `name`, `notes`, `$ano` 'saldo' `contas` ..."; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -