我如何在MySQL中将图像从mysql显示到表中

时间:2018-10-12 07:02:37

标签: php

$servername = "localhost"; $username = "root"; $password   = ""; $database   = "cyclist";
$conn= new mysqli($servername,$username,$password,$database );

$sql="SELECT * FROM slider "; $result=mysqli_query($conn,$sql);


<table id="example2" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>S.No</th>
            <th>Slider Image</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
<?php while ($row = mysqli_fetch_assoc($result)) { ?>
        <tr>
            <td><?php echo $row['pk_slider_id'] ?></td>
        echo "<tr><td>".$row['slider_image']."</td><td><img src='img/".$row[slider_image].".png' style='width:175px;height:75px;'/></td></tr>";
            <td>

1 个答案:

答案 0 :(得分:0)

尝试此代码;

 $servername = "localhost"; $username = "root"; $password   = ""; $database   = "cyclist";
    $conn= new mysqli($servername,$username,$password,$database );

    $sql="SELECT * FROM slider "; $result=mysqli_query($conn,$sql);


    <table id="example2" class="table table-bordered table-hover">
        <thead>
            <tr>
                <th>S.No</th>
                <th>Slider Image</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
    <?php while ($row = mysqli_fetch_assoc($result)) { 

         $image=$row[slider_image];

    ?>
            <tr>
                <td><?php echo $row['pk_slider_id'] ?></td>
      <tr><td><img src=<?php echo $image;?> style="width:175px;height:75px;"/></td></tr>
                <td></td>
<?php } ?>