简体   繁体   English

在显示数据库内容方面需要帮助

[英]Need help with displaying database content

Here's what I am trying to achieve:这是我想要实现的目标:在此处输入图像描述 I'm using MYSQLi objectively.我客观地使用MYSQLi。

I connect to the database with:我通过以下方式连接到数据库:

<?php  
$mysqli= new mysqli( 
'xxxxx', #host 
'xxxxx', #username 
'xxxxx', #password 
'xxxxx'); #database name 

if ($mysqli->connect_error) 
{   
die("Connect Error: $mysqli->connect_error");
}
?>

I have an auto-incrementing ID field, a 'Title' Field, 'Description' field and a field which contains the URL to an image so I can use我有一个自动递增的 ID 字段、一个“标题”字段、“描述”字段和一个包含 URL 到图像的字段,所以我可以使用

<img src="<url from database>" alt="<title from database>" />

I need to have it formatted the same way as the picture and I'm stuck on how to separate the data so each row is formatted this way to form what will be a portfolio of artwork.我需要将其格式化为与图片相同的格式,并且我坚持如何分离数据,因此每一行都以这种方式格式化以形成艺术品组合。

Doing this for a school project so any help is greatly appreciated.为学校项目这样做,因此非常感谢任何帮助。

$result = $mysqli->query('SELECT title, description, image FROM table;');

while($o = $result->fetch_object()) {
  echo '<div class="image">';
  echo '<img src="', htmlspecialchars($o->image),'" alt="', htmlspecialchars($o->title),'" />';
  echo '<h3>', htmlspecialchars($o->title), '</h3>';
  echo '<p>', htmlspecialchars($o->description), '</p>';
  echo '</div>';
}

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

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