简体   繁体   English

如何从保存在数据库中的链接在 php 页面中显示图像

[英]how to show images in php page from link saved in DB

So if you feel the question is repeated ,I have tried other solutions but not working.I have link of images stored in Database(phpMyAdmin) as string.I want to load the image as a part of the second column of a table from DB using the links.因此,如果您觉得问题重复了,我已经尝试了其他解决方案但没有奏效。我将图像链接存储在数据库(phpMyAdmin)中作为字符串。我想将图像作为数据库表第二列的一部分加载使用链接。

<table style="width:100%" id="to1">
  <tr>
    <th>ID</th>
    <th>Featured Image</th> 
    <th>Title</th>
    <th>Brand Name</th>
    <th>Price</th>
    <th>Quantity</th>
    <th>Shipping Cost</th>
    <th>Delivery Time </th>
    <th>Delivery Distance</th>
  </tr>
  <?php
    $conn = mysqli_connect("localhost","root", "", "products");
    if ($conn-> connect_error){
        die("Connection Failed: ". $conn-> connect_error);
    }

    $sql = "SELECT id,featured_image,title,brand_name,price,quantity,shipping_cost,delivery_time,delivery_distance from products";
    $result = $conn-> query($sql);

    if ($result-> num_rows > 0){
        while ($row = $result-> fetch_assoc()){
            $val = $row["featured_image"];
            echo "<tr><td>".$row["id"] ."</td><td>". '<img src='<?= **HERE** ?>' alt="">' ."</td><td>".$row["title"] ."</td><td>".$row["brand_name"] ."</td><td>".$row["price"] ."</td><td>".$row["quantity"] ."</td><td>".$row["shipping_cost"] ."</td><td>".$row["delivery_time"] ."</td><td>".$row["delivery_distance"] ."</td></tr>";  
        }
        echo "</table>";    
    }
    else{
        echo "0 tables";
    }

    $conn-> close();
  ?>

I have shown the place as here .please suggest some ways so that I can show images instead of links in the table.我已经把这个地方显示为这里。请提出一些建议,以便我可以在表格中显示图像而不是链接。 Here is what I want it to look like.就是我想要的样子。

I think, you had quotes problems:我想,你有报价问题:

UPDATED:更新:

echo "<tr><td>".$row["id"] ."</td><td><img src='".$row["featured_image"]."' alt=''></td><td>".$row["title"]."</td><td>".$row["brand_name"]."</td><td>".$row["price"]."</td><td>".$row["quantity"]."</td><td>".$row["shipping_cost"]."</td><td>".$row["delivery_time"]."</td><td>".$row["delivery_distance"] ."</td></tr>";
    echo "
<tr>
<td>.$row["id"].</td>
<td>.<img src='$row["featured_image"]' alt="">.</td>
<td>.$row["title"].</td>
<td>.$row["brand_name"].</td>
<td>.$row["price"].</td>
<td>.$row["quantity"].</td>
<td>.$row["shipping_cost"].</td>
<td>.$row["delivery_time"].</td>
<td>.$row["delivery_distance"].</td>
</tr>"

Try this尝试这个

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

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