search
HomeBackend DevelopmentPHP ProblemHow to print pictures from database in php

Whether it is website design, office system, or shopping mall, pictures need to be displayed on the web page. The pictures are extracted from the database. Next, let’s take a look at how to save and display pictures through the picture path:

How to print pictures from database in php

First, save the path of the image in the table. Note: the path starts from the WWW directory rather than from the disk root. / represents the WWW directory: (recommended Study: PHP video tutorial)

How to print pictures from database in php

The img in the table is the stored image path, which is the path under the WWW directory. Since the path is stored in the table , then we can connect to the database through PHP to obtain:

<?php
    require "DBDA.class.php";//调用封装类
    $db = new DBDA();
    $sql = "select * from book";
    $arr= $db->query($sql);
    foreach($arr as $v) // 遍历出各个列的内容
    {
        //图片用img标签获取路径,因为遍历出的img是$v[5],所以路径就是$v[5]
        echo "<div id=&#39;hang&#39;><a href=&#39;gouwu.php?bkid={$v[0]}&#39;><img  src="/static/imghwm/default1.png"  data-src="https://img.php.cn/upload/image/648/417/412/1571107706724528.png?x-oss-process=image/resize,p_40"  class="lazy"     style="max-width:90%"How to print pictures from database in php" ></a>
              <div class=&#39;jg&#39;><a href=&#39;gouwu.php?bkid={$v[0]}&#39;>{$v[1]}</a></div>
              <div class=&#39;jg&#39; style=&#39;color:red&#39;>{$v[3]}元</div>
              </div>
              ";
              
    }

?>

In this way, we can obtain the image through the path, which is very convenient and efficient:

How to print pictures from database in php

The above is the detailed content of How to print pictures from database in php. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools