PHP & MySQL: fetch images from database

后端 未结 8 987
夕颜
夕颜 2021-02-08 13:06

I have uploaded multiple images and path of all the images have been stored together.

Using explode I have separated them and now I wish to echo them in a c

相关标签:
8条回答
  • 2021-02-08 13:49

    Change your echo statement with :

    echo "<div class='fill' style='background-image:url(http://devoirtechnologies.in/localhealthorganization/".$item.");'></div>";
    

    and also set the width and height of this div. Because default height of the div is 0 (zero).

    0 讨论(0)
  • 2021-02-08 13:53

    Try this it will help :

    Use this :

    <img src="<?php echo $row["offimage"]; ?>"></img>
    

    instead of

    $str= $row["offimage"];
    

    if you want to display the image.

    Code :

    <?php
        $con=mysqli_connect("localhost","root","","db");
        // Check connection
        if (mysqli_connect_errno())     {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        $parentid = $_GET['country'];
        $id = $_GET['fid'];
    
        $sql = "SELECT * FROM register_office WHERE id='".$id."'";
        $result = mysqli_query($con, $sql);
        if (mysqli_num_rows($result) > 0) 
            {
                echo "<div class='item active'>";
                   do
                        {
                         $str= $row["offimage"];
                                    $array =  explode('*', $str);
                                    foreach ($array as $item) 
                                        {
                                            echo "<div class='fill'>";
                                            echo "<img src=\"http://example.com/abc/" . $item . "\" height=\"500\" width=\"2000\"/>"; 
                                            echo "</div>";
                                }   
                      } while($rs = mysqli_fetch_array($result));
                    echo "</div>";
    
            }
        else 
            {
                echo "0 results";
            }
    ?>
    
    0 讨论(0)
提交回复
热议问题