如何在sql表的右列中显示图像?

时间:2019-07-04 09:23:49

标签: php html mysql

我正在将值插入sql表并通过AJAX显示它。值会正确显示,但图像不在右列,而是在顶部。为什么会这样?

尽管图像显示在网页中,但是图像在不同位置对齐。 enter image description here

<?php
...
...
...
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
 $output .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <tr>
     <th>ID</th>
     <th>Name</th>
     <th>Time</th>
     <th>Img</th>
    </tr>
 ';
 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["ID"].'</td>
    <td>'.$row["Name"].'</td>
    <td>'.$row["Time"].'</td>
    <td>' ?> <img src="<?php echo $row['Img']; ?>" alt="my picture" height="100" width="100" /> <?php '</td>  //Here is the problem where I am trying to display the image
   </tr>
  ';

 }
 echo $output;
}
else
{
 echo 'Data Not Found';
}

?>

1 个答案:

答案 0 :(得分:1)

if(mysqli_num_rows($result) > 0)
{
 $output .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <tr>
     <th>ID</th>
     <th>Name</th>
     <th>Time</th>
     <th>Img</th>
    </tr>
 ';
 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["ID"].'</td>
    <td>'.$row["Name"].'</td>
    <td>'.$row["Time"].'</td>
    <td> <img src="' .$row["Img"] . '" alt="my picture" height="100" width="100" /> </td>  //Here is the problem where I am trying to display the image
   </tr>';
 }
 $output .= '</table></div>';
 echo $output;
}
else
{
 echo 'Data Not Found';
}

尝试这种方式。