dongqie4402 2017-07-05 10:45
浏览 37
已采纳

使用表中的图像显示MySQL数据

I have set up a table that displays data from my SQL database using

 $sql = "SELECT company_id, stk_buy, stk_sell FROM price";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
       echo "<table><tr><th>ID</th><th>Company</th><th>Buying Price</th><th>Selling Price</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["company_id"]."</td><td>".$row["stk_buy"]."</td><td>".$row["stk_sell"]."</td></tr>";
    }
    echo "</table>";
   } else {
       echo "0 results";
   }

I want to have images display in the Company column, different ones in each row. Similar to: enter image description here Is there a possible way of displaying images with my current html table setup or do I have to fetch each row to display images?

  • 写回答

3条回答 默认 最新

  • doushi5024 2017-07-05 11:00
    关注

    You need to fetch the image name from the database, after fetching the images you need to put it inside a <IMG src=""> tag.

    The source of the image considering the img as you mention in the comment.

    SQL: $sql = "SELECT company_id, stk_buy, stk_sell FROM price";

    echo "<tr><td>".$row["company_id"]."</td><td><img src='img/".$row[company_id].".png' style='width:175px;height:75px;'/></td><td>".$row["stk_‌​buy"]."</td><td>".$r‌​ow["stk_sell"]."</td‌​></tr>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型