drv13270 2017-10-15 04:52
浏览 166

如何使用PHP将图像显示到表格中?

I have a table in the database where it contains image,name,location. I tried to display the name and location, both got displayed. But i struck at how to display the image in the table td. I have almost 4 to 5 rows in the table .

Below is the code which I used.

HTML:

<?php 
echo "<table border='1'>";
echo "<tr><th>Hotel</th><th>Location</th></tr>";
$i=1;
$html="";
foreach($one as $id => $key):

    $html .= "<tr>";
    $html .= "<td>".$one[$id]."</td>";
    $html .= "<td>".$two[$id]."</td>";
    $html .= "<td>".$three[id]."</td>";
    $html .= "</tr>";
endforeach;
$html .= "</table>";

echo $html;
    ?>

PHP:

<?php 
    session_start();
    $link = mysqli_connect('localhost','root','','hotels');
    if(isset($_POST['sub']))
    {
        // mysqli_s(elect_db($link, "hotels");
        $location=$_POST['searchVal'];
        $sql = "select * from rooms where location = '$location'";
        $sqldata= mysqli_query($link ,$sql);

        while($row = mysqli_fetch_array($sqldata)){

            $one[] = $row['name'];
            $two[] = $row['location'];
            $three[] =$row['Image'];


    }


    ?>

Output. I am getting some symbols like this: (check this output here)

Can anyone please help me out to solve this displaying of image into table.

  • 写回答

1条回答 默认 最新

  • douguo7431 2017-10-15 07:22
    关注

    Actually before I directly uploaded the image into the database. Now i took a folder and placed the image. And the path of that image is stored in the data based. After retrieving it made me easy to get the image as it checks for the path.

    Now i got the image. Thank you so much.

    Changes done in code is:

    **PHP**
    
    <?php 
        session_start();
        $link = mysqli_connect('localhost','root','','hotels');
        $three="";
        $one = "";
        $two="";
        if(isset($_POST['sub']))
        {
            // mysqli_s(elect_db($link, "hotels");
            $location=$_POST['searchVal'];
            $sql = "select * from rooms where location = '$location'";
            $sqldata= mysqli_query($link ,$sql);
    
            while($row = mysqli_fetch_array($sqldata)){
    
                $three[] = $row['image'];
                $one[] = $row['name'];
                $two[] = $row['location'];
            }
        }
    
    
        ?>
    
    **HTML**
    
    <?php 
    
                        echo "<table border='1'>";
                        //echo "<tr><th>Hotel</th><th>Location</th></tr>";
                        $i=1;
    
                        foreach($one as $id => $key):
    
                            echo "<tr>";
                             echo "<td>";?><img src="<?php echo $three[$id];?>" height="100" width="100"><?php echo "</td>";
                            echo "<td>".$key."</td>";
                            echo "<td>".$two[$id]."</td>";
    
                            echo "</tr>";
                            $i++;
                        endforeach;
                        echo "</table>";
    
                            ?>
    

    Thank You.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP