繁体   English   中英

如何从php中的mysql数据库获取图像

[英]How to get the an image from mysql database in php

我有这段代码应该在mysql数据库中搜索图片,不确定它是否有效,

我想获取用户搜索的图像并将它们发布在 html 中,我可以这样做吗?

这是我的代码

<?php 
    require('connect.php');
      if(isset($_POST['submit'])){ 
      if(isset($_GET['go'])){ 
      if(preg_match("/^[  a-zA-Z]+/", $_POST['name'])){ 
      $name=$_POST['name']; 
      //connect  to the database 
      //-query  the database table 
      $sql="SELECT * FROM cards WHERE name LIKE '%$searchQuery'"; 
      //-run  the query against the mysql query function 
      $result=mysql_query($sql); 
      //-create  while loop and loop through result set 
      while($row=mysql_fetch_array($result)){ 
              $name = $row['name'];
                $id = $row['id'];
      } 
      } 
      else{ 
      echo  "<p>Please enter a search query</p>"; 
      } 
      } 
      } 
    ?> 

显示图像[您在数据库中存储图像路径的位置]

您只需使用图像标签回显列

echo "<img src =".$row['name'].">"; 

笔记 :

您应该将图像指向图像存储在文件中的路径

就像是

echo "<img src ='assets/images/".$row['name']."'>"

暂无
暂无

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

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