简体   繁体   中英

How to get information from SQL table with php

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;
}
?>

Change from

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

into

$statement = $conn->query($sql)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM