Search code examples
phpmysqlphppowerpointphppresentation

How to add two images per slide from mysql (PHP Presentation)?


I am trying to make simple presentation with two images per slide but I don't know how to put 2 images per slide. All images goes to one slide.

This is how it looks enter image description here

This is what I want enter image description here

Could you please help me with this. This is my code: (THIS CODE IS NOW FIXED)

$counter = 0;
$query = "SELECT izvestaji.operacija, izvestaji.ucinak, izvestaji.id, projekti.naziv, operacije.nazivEng FROM izvestaji INNER JOIN projekti ON izvestaji.projekatId=projekti.id INNER JOIN operacije ON izvestaji.operacijaId=operacije.id WHERE izvestaji.datum='$datum' AND izvestaji.projekatId='$projekatId'";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {

            // Create a slide
            echo date('H:i:s') . ' Create templated slide' . EOL;


            // Shape
            echo date('H:i:s') . ' Create a shape (rich text)' . EOL;

            $id = $row['id'];

            $query2 = "SELECT img_name FROM slike WHERE izvestajId='$id' AND datum='$datum'";
            $result2 = mysqli_query($con, $query2);

            while ($row2 = mysqli_fetch_array($result2)) {

            if ($counter % 2 == 0) {
                $currentSlide = createTemplatedSlide($objPHPPresentation);
                $shape1 = $currentSlide->createDrawingShape();
                $shape1->setName('Part page');
                $shape1->setDescription('Page');
                $shape1->setPath('../../../../files/izvestaji/' . $project . '/' . $datum . '/' . $row['nazivEng'] . '/' . $row2['img_name']);
                $shape1->setResizeProportional(false);
                $shape1->setOffsetX(75);
                $shape1->setOffsetY(300);
                $shape1->setHeight(400);
                $shape1->setWidth(400);
            } else {
                $shape1 = $currentSlide->createDrawingShape();
                $shape1->setName('Part page');
                $shape1->setDescription('Page');
                $shape1->setPath('../../../../files/izvestaji/' . $project . '/' . $datum . '/' . $row['nazivEng'] . '/' . $row2['img_name']);
                $shape1->setResizeProportional(false);
                $shape1->setOffsetX(495);
                $shape1->setOffsetY(300);
                $shape1->setHeight(400);
                $shape1->setWidth(400);

            }
                $counter++;
            }
     $counter = 0;
}

You can see full code ON THIS LINK


Solution

  • You need to create a new slide every two images. Move this line:

    $currentSlide = createTemplatedSlide($objPHPPresentation);
    

    to here:

    if ($counter % 2 == 0) {
        $currentSlide = createTemplatedSlide($objPHPPresentation);
        $shape1 = $currentSlide->createDrawingShape();
        // ...