doujia5863 2014-08-10 07:38
浏览 31
已采纳

我无法使用MYSQLi获取我的图像

I'm struggling to transfer my files to MYSQLi. I've managed to get my data into a table adapting code from an online tutorial but I can't find anything that tells me how to get the image into the table. I've tried all sorts of wrong ways which obviously didn't work. This is the latest. Can anyone put me on the right track? It works fine without the images. The field is called Images. Could that be a problem?

<?php

$mysqli = new mysqli('localhost','user','password','data_base');

if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$results = $mysqli->query("SELECT * FROM engravers");

print '<table border="1" >';
while($row = $results->fetch_assoc()) {
print '<tr>';
print '<td>'.$row["Key"].'</td>';
print '<td>'.$row["Country"].'</td>';
print '<td>'.$row["Year"].'</td>';
print '<td>'.$row["Description"].'</td>';
print '<td>'.$row["Engraver1Surname"].'</td>';
print '<td>'.$row["Designer1Surname"].'</td>';
print '<td>'.$row["Printer"].'</td>';

   $img_url = "http://www.xxxx.net/images/"; 
   { 
    print  '<td>'<img src="'.$img_url.$row['Images'].'" />'</td>'; 

print '</tr>';
}  
print '</table>';


$results->free();

$mysqli->close();
?>
  • 写回答

1条回答 默认 最新

  • duanchuang3182 2014-08-10 07:56
    关注

    you forgot to put img tag in ''. so just try this:

      print  '<td>'.'<img src="'.$img_url.$row['Images'].'" />'.'</td>'; 
    

    also its better to put $img_url before the while loop:

      $img_url = "http://www.xxxx.net/images/"; // put this before while 
      print '<table border="1" >';
      while($row = $results->fetch_assoc()) {
      print '<tr>';
      print '<td>'.$row["Key"].'</td>';
      print '<td>'.$row["Country"].'</td>';
      print '<td>'.$row["Year"].'</td>';
      print '<td>'.$row["Description"].'</td>';
      print '<td>'.$row["Engraver1Surname"].'</td>';
      print '<td>'.$row["Designer1Surname"].'</td>';
      print '<td>'.$row["Printer"].'</td>';
      print  '<td>'.'<img src="'.$img_url.$row['Images'].'" />'.'</td>'; // put the img tag in ''
      print '</tr>';
      }  
      print '</table>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败