PHP & MySQL: fetch images from database

后端 未结 8 897
夕颜
夕颜 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:39

    this is all the codes in the link:

    1. I fetch 4 images in ACTIVE corousel holder and 4 in ITEM. So, there are 2 slides which contains 4 images inside it.
    2. I use PDO to handle it. it's so simple scripting with little errors and easy to debug.

    CONNECT TO database with PDO:

     PDO::ERRMODE_WARNING)); }
    catch (PDOException $e){echo 'Database Server Goes Down or Not Available!';}
    ?>
    

    then, fetch the images:

    prepare("SELECT * FROM table_name WHERE item=:item ORDER BY id ASC LIMIT 4,8"); $queryz->execute(); $data = $queryz->fetchAll(); foreach ($data as $row){ $id=$row['id']; $imagez=$row['imagez']; ?>
    Rp.
    discz: %

    Beli Info »

    prepare("SELECT * FROM table_name WHERE item=:item ORDER BY RAND() LIMIT 4,8"); $queryz->execute(); $data = $queryz->fetchAll(); foreach ($data as $row){ $id=$row['id']; $imagez=$row['imagez']; ?>
    Rp.
    discz: %

    Beli Info »

    Then, you focus on how to fetch the image. the code is like in this following:

                                        <
    
    div class="item active">
                                                prepare("SELECT * FROM table_name WHERE item=:item ORDER BY id ASC LIMIT 4,8");
                                                $queryz->execute();
                                                $data = $queryz->fetchAll();
                                                foreach ($data as $row){
                                                    $id=$row['id'];
                                                    $imagez=$row['imagez'];
                                                    ?>
                                                    
    Rp.
    discz: %

    Beli Info »

    The PATH OF THE IMAGES stored in:

    $imagez=$row['imagez'];
    

    which has the same directory with

    ../myimage/defaultimg.jpg"
    

    Note: I'm so sorry for not expert in explanation, but that's I wrote the code in the web page. But, I suggest you to copy the code and change what you need to then try again.

提交回复
热议问题