简体   繁体   English

如何使用php从SQL表中获取信息

[英]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. 所以我已经创建了一个关于SQL的数据库,我试图从我需要的一个表中获取信息(id,title和date)并制作一个html元素但是当我运行该函数时没有任何反应。

<?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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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