1

So i've created a database on SQL, i'm trying to get information (id,title and date)out of one of the tables i need and make an html element of it but when i run the function nothing happens.

<?php
function getTitles (){
$conn;
$sql='SELECT * FROM `thumbnails`';

$statement = $conn->prepare($sql);
$statement->bindValue(":title_id",$title_id);
$statement->execute();
$titles = $statement->fetchAll();
$output='';
foreach($titles as $title) {
    $output .='<div class="col-4 thumbnails"><img src="../stlye/images/art'.$title['id'].'.jpg" class="img-flexible">
        <h2>'.$title['title'].'</h2>
        <p class="time"><time>'.$title["date"].'</time></p></div>';
}
return $output;
}
?>
Juan
  • 23
  • 3
  • Why you are binding ? – Hassaan Dec 13 '16 at 11:17
  • Did you check for errors? http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display http://php.net/manual/en/mysqli.error.php http://php.net/manual/en/pdo.errorinfo.php –  Dec 13 '16 at 11:17
  • Does both of your tables contains **exactly** the columns : `id`, `title` and `date` ? – Anwar Dec 13 '16 at 11:19

1 Answers1

0

Change from

$statement = $conn->prepare($sql);
$statement->bindValue(":title_id",$title_id);
$statement->execute();

into

$statement = $conn->query($sql)
Hassaan
  • 6,355
  • 5
  • 25
  • 44