-1

我做了一个简单的演示,并从 mysql 获取文本和图像。例如,我有一个文本和 5 个图像。每张幻灯片必须有 2 张图片。但问题是每张幻灯片上的 while 循环中的文本都重复。

例子:

This is how it works now:                         I want this:
-----------                                       ----------------
Slide1                                            Slide1
text 1                                            text 1
2 images                                          2 images
-----------                                       ----------------
-----------                                       ----------------
Slide2                                            Slide2
text 1                                        
2 images                                          2 images
-----------                                       ----------------
-----------                                       ----------------
Slide3                                            Slide3
text2        
1 image                                           1 image
----------                                        ----------------

这就是问题所在: 在此处输入图像描述 我想从第二张和第三张幻灯片中删除重复的文本。这是我的代码

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

            $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 ($brojacslikapostrani % 2 == 0) {
                    $currentSlide = createTemplatedSlide($objPHPPresentation);

                    //Pozadina
                    $oBkgImage = new Image();
                    $oBkgImage->setPath('./resources/background.png');
                    $currentSlide->setBackground($oBkgImage);

                    $shape = $currentSlide->createRichTextShape();
                    $shape->setHeight(100)
                          ->setWidth(930)
                          ->setOffsetX(10)
                          ->setOffsetY(20);
                    $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);

                    $textRun = $shape->createTextRun(strtoupper($row['nazivEng']));
                    $textRun->getFont()->setBold(true)
                          ->setSize(48)
                          ->setName('Times New Roman')
                          ->setColor($colorBlack);


                    // ----------- THIS CODE MAKES THE PROBLEM ------------------------
                        echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
                        $shape = $currentSlide->createRichTextShape()
                              ->setHeight(600)
                              ->setWidth(930)
                              ->setOffsetX(10)
                              ->setOffsetY(130);
                        $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)
                              ->setMarginLeft(25)
                              ->setIndent(-25);
                        $shape->getActiveParagraph()->getFont()->setSize(20)
                              ->setName('Times New Roman')
                              ->setColor($colorBlack);
                        $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);


                        $shape->createTextRun($row['operacija'])->getFont()->setBold(true);
                        $shape->createTextRun(": ")->getFont()->setBold(true);
                        $shape->createTextRun($row['ucinak']);
                    //------------------------------------------------------------------------

                    $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);
                }

                $brojacslikapostrani++;
            }
            $brojacslikapostrani = 0;

      }
```
4

1 回答 1

1

如果您只想打印一次文本,则创建存储信息的变量,无论信息是否已打印。另外包装通过条件语句打印信息的代码(如果有什么......),然后检查是否满足条件(在您的情况下,如果信息未打印),如果满足条件,则将打印信息,否则不是。

请参阅评论添加并修改代码如下

<?
$brojacslikapostrani = 0;
$query1 = "SELECT izvestaji.operacija, izvestaji.ucinak, izvestaji.id, operacije.nazivEng FROM izvestaji INNER JOIN operacije ON izvestaji.operacijaId=operacije.id WHERE izvestaji.datum='$datum' AND izvestaji.projekatId='$projekatId'";
$result1 = mysqli_query($con, $query1);
while ($row = mysqli_fetch_array($result1)) {           

            $id = $row['id'];

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

            $textPrinted = false; #<= ADDED
            while ($row2 = mysqli_fetch_array($result2)) {

                if ($brojacslikapostrani % 2 == 0) {
                    $currentSlide = createTemplatedSlide($objPHPPresentation);

                    //Pozadina
                    $oBkgImage = new Image();
                    $oBkgImage->setPath('./resources/background.png');
                    $currentSlide->setBackground($oBkgImage);

                    $shape = $currentSlide->createRichTextShape();
                    $shape->setHeight(100)
                          ->setWidth(930)
                          ->setOffsetX(10)
                          ->setOffsetY(20);
                    $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);

                    $textRun = $shape->createTextRun(strtoupper($row['nazivEng']));
                    $textRun->getFont()->setBold(true)
                          ->setSize(48)
                          ->setName('Times New Roman')
                          ->setColor($colorBlack);


                    // ----------- THIS CODE MAKES THE PROBLEM ------------------------
                    #<= ADDED 2lines
                    if ($textPrinted === false) {
                        $textPrinted = true;

                        echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
                        $shape = $currentSlide->createRichTextShape()
                              ->setHeight(600)
                              ->setWidth(930)
                              ->setOffsetX(10)
                              ->setOffsetY(130);
                        $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)
                              ->setMarginLeft(25)
                              ->setIndent(-25);
                        $shape->getActiveParagraph()->getFont()->setSize(20)
                              ->setName('Times New Roman')
                              ->setColor($colorBlack);
                        $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);


                        $shape->createTextRun($row['operacija'])->getFont()->setBold(true);
                        $shape->createTextRun(": ")->getFont()->setBold(true);
                        $shape->createTextRun($row['ucinak']);

                    } #<= ADDED
                    //------------------------------------------------------------------------

                    $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);
                }

                $brojacslikapostrani++;
            }
            $brojacslikapostrani = 0;

      }
于 2019-11-06T21:03:47.847 回答