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
Post a Comment