简体   繁体   中英

I can't get my images with 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();
?>

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>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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