So I'm trying to create a dynamic SELECT query that will only show the columns that were chosen previously and stored in a string $stANCol.
$idServ = 17; //$_GET(Selected);
$queryIsSelected = "SELECT $stANCol FROM camposservico WHERE idServico = ? ;";
$stmt = $mydb->prepare($queryIsSelected);
$stmt->bind_param("i", $idServ);
$stmt->execute();
The echo from $stANCol is
morada, dieta, dataIntervencao, sondaVesical, ecd,
sinaisVitais, riscoQueda, riscoAlergia, riscoTransfusao, riscoMultiRisco, obsQuadro, obs
and these are the columns that may change depending on what is selected or not.
The echo from $queryIsSelected is
SELECT morada, dieta, dataIntervencao, sondaVesical, ecd,
sinaisVitais, riscoQueda, riscoAlergia, riscoTransfusao,
riscoMultiRisco, obsQuadro, obs FROM camposservico WHERE idServico = ? ;
And this query works just fine on phpMyAdmin, hence my question. Am I doing something wrong or is it impossible to have a string variable used on the SELECT?
EDIT: Turns out there was nothing wrong with any of this code, had a pending statement lurking on my page that was messing with this one. Thanks for all the replies everyone :)
SELECT * FROM camposservico WHERE idServico = ?work?