-1

PHP code is:

class Gallery{

    public function get_images(){
        global $pdo;

        $query = $pdo->prepare('SELECT * FROM gallerys order by id desc');
        $query->execute();

        return $query->fetchAll(PDO::FETCH_ASSOC);
    }

        public function fetch_data($pid){
        global $pdo;

        $query = $pdo->prepare('SELECT * FROM gallerys where id = ? order by id desc');
        $query->BindValue(1,$pid);
        $query->execute();

        return $query->fetch();
    }
}

HTML code is:

$post  = new Gallery;
$check = new Gallery;
$galery = $post->get_images();

<?php foreach($galery as $post){?>
<div class="fw-carousel fl-wrap full-height lightgallery">
<div class="slick-slide-item">
<div class="box-item">
<img src="../asset/<?php echo $post['image'];?>" alt="">
<a href="../asset/<?php echo $post['image']?>" class="gal-link popup-image"><i class="fa fa-search"  ></i></a>
</div>
</div>
</div>
<?php }?>

Database structure:

---id---name---user---post_date---image---

When user post something and put 3 images into table gallerys on column user```` will be places$_SESSION['user_id'];and with that i will retrieve images byuser_id``` now i get only 1 image not all example 3 or 5 or 10...

When user upload example 3 or 5 images into database and want to view his upload, with this code they will get only 1 image, not all image what he upload. I don't get where is the problem in this script.

Any help?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mark
  • 25
  • 5
  • what is the output of die(print_r($galery)); after $galery = $post->get_images();? – MThiele Oct 02 '19 at 07:07
  • Please [see how to solve your problem or make your question on topic](https://phpdelusions.net/pdo/mcve) (which currently isn't) – Your Common Sense Oct 02 '19 at 07:08
  • I get only one image but in database i have 3. @MThiele – Mark Oct 02 '19 at 07:11
  • There is no `__construct` method in your `Gallery` class – Professor Abronsius Oct 02 '19 at 07:11
  • What you mean? Code for retrieve all images or? @RamRaider – Mark Oct 02 '19 at 07:14
  • usually a class will be instantiated automatically when you call `new Gallery` because it has a method called `__construct` - Have a look at https://stackoverflow.com/questions/455910/what-is-the-function-construct-used-for for more – Professor Abronsius Oct 02 '19 at 07:18
  • @RamRaider his class is already instantiated. – Your Common Sense Oct 02 '19 at 07:19
  • Yes, and i have problem to retrieve all images from ```gallerys``` because they retreve me only ```1``` image not ```all``` @RamRaider – Mark Oct 02 '19 at 07:21
  • There must be other code then - is it not either via `__construct` or by a method of the same name as the class, ie: `public function Gallery(){}` within the class? – Professor Abronsius Oct 02 '19 at 07:21
  • ```public function get_images(){``` and ```public function fetch_data($pid){``` with this functions i retreve all from database using that code in ```HTML code is:``` take a look @RamRaider – Mark Oct 02 '19 at 07:23
  • Could it be that you do actually retrieve all images, but that they overlap when displayed? Have you checked the source code of the web page? – KIKO Software Oct 02 '19 at 07:25
  • Have you check your connection source either your connected to correct database? Seem like no issues with the code. – 502_Geek Oct 02 '19 at 07:28
  • In database i have picture with same names ```maybe there is the problem``` but another is why they don't display me that 3 images. In source code i have 3 ```
    ``` this ```div's``` so they display me 3 images but not on page not 3 images just preview 1 @KIKOSoftware
    – Mark Oct 02 '19 at 07:29
  • Connection is right @D3adL0cK – Mark Oct 02 '19 at 07:29
  • So, your `$galery = $post->get_images();` have 3 images return ? – 502_Geek Oct 02 '19 at 07:34
  • Yes, but on page displayed is only 1 image... In my case need to display all images in that 3 ```div's``` @D3adL0cK – Mark Oct 02 '19 at 07:35
  • Take a look at the source of your page and see if there are 3 images. *Stab in the dark*: place your `foreach` loop _inside_ of ` – brombeer Oct 02 '19 at 07:36
  • That is work now, they display me 3 images. Thanks a lot mate! @kerbholz – Mark Oct 02 '19 at 07:39
  • No problem, glad it works – brombeer Oct 02 '19 at 07:44

1 Answers1

0

You're generating a carousel/gallery/slider for each of your three images, overlapping each other. What you want is to create one carousel/gallery/slider with your three images inside. Replace

<?php foreach($galery as $post){?>
<div class="fw-carousel fl-wrap full-height lightgallery">
<div class="slick-slide-item">
<div class="box-item">
<img src="../asset/<?php echo $post['image'];?>" alt="">
<a href="../asset/<?php echo $post['image']?>" class="gal-link popup-image"><i class="fa fa-search"  ></i></a>
</div>
</div>
</div>
<?php }?>

with

<div class="fw-carousel fl-wrap full-height lightgallery">
  <?php foreach($galery as $post){?>
  <div class="slick-slide-item">
    <div class="box-item">
      <img src="../asset/<?php echo $post['image'];?>" alt="">
      <a href="../asset/<?php echo $post['image']?>" class="gal-link popup-image"><i class="fa fa-search"  ></i></a>
    </div>
  </div>
  <?php }?>
</div>
brombeer
  • 8,716
  • 5
  • 21
  • 27