I'm trying to retrieve records from the mySQL-database but nothing gets selected. I'm using the below php function:
function printButton($conn){
$your_variable = 1;
$knappar = $conn->prepare('SELECT * FROM knappar WHERE pid < :parameter');
$knappar->bindParam(':parameter', $your_variable, PDO::PARAM_INT);
$knappar->execute();
//Loops boxes
$count = 1;
while ($row = $knappar->fetch(PDO::FETCH_ASSOC)) {
echo "<a href='#'><div class='box' id='div_item".$count."'>";
echo $row['header'];
echo $row['id'];
echo "</div></a>";
$count = $count + 1;
}
}
It works fine if I change "WHERE pid = 1" instead of the "< :parameter". What am I doing wrong?
I updated it to what it looks like now:
function printButton($conn){
$your_variable = 1;
$knappar = $conn->prepare('SELECT header FROM knappar WHERE pid < :parameter');
$knappar->bindParam(':parameter', $your_variable, PDO::PARAM_INT);
$knappar->execute();
//Loops boxes
$results = $knappar -> fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $row){
echo $row['header'];
echo '<br />';
}
}
With above example, still no output. pid value is int(11) in the database and the value of all rows are 1.