dqm4675
dqm4675
2019-07-04 09:23

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

已采纳

I am inserting values to an sql table and displaying it through AJAX. The values get displayed properly but the image does not come in the right column, instead it comes on top. Why does this happen?

Although the image is shown in the webpage, it is however aligned in different position. 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条回答

  • duanbinmi8970 duanbinmi8970 2年前
    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';
    }
    

    try this way.

    点赞 评论 复制链接分享

为你推荐