Skip to content
Advertisement

How do I display a row once inside a looped rows using php?

I have a problem on displaying a row once inside a looped rows using PHP. Here is the exact code that I have:

Figure 1 `

if (sizeof($items) > 0) {
   foreach ($items as $item) {
      //customisation starts - jm 10:54 AM 20/11/2018
      //if block for material type
            $this->data->currentItem = $item;
            if ($item->getType() == 0) {
                $this->getRow($this->style->itemList['rows']['materialSubHeader'], false, 'currentHeader', $withHeader);
                $this->getRow($this->style->itemList['rows']['matContent'], false, 'currentHeader', $withHeader);
            }
            if ($item->getType() == 1) {
                $this->getRow($this->style->itemList['rows']['lbrContent'], false, 'currentHeader', $withHeader);
            }
            $withHeader = false;
            $this->currentHeader = $otherHeader;
            //customisation ends - jm 10:54 AM 20/11/2018
        }
    }
}

`

This line have a row containing a label “Material”

from this photo

Subheader Material is repeating

This Materials should not repeat on the looped contents.

On this code below based on figure 1 above this post This code is responsible for displaying the label Material that is looped

$this->getRow($this->style->itemList['rows']['materialSubHeader'], false, 'currentHeader', $withHeader);

On this code below based on figure 1 This code is responsible for displaying the content

$this->getRow($this->style->itemList['rows']['matContent'], false, 'currentHeader', $withHeader);

How can I stop the iteration of the first row.

Thanks in advance

Advertisement

Answer

Here’s my solution. First, add key to your foreach loop:

foreach ($items as $key=>$item) {

Then, execute the code that display the Material label if only the key is 0:

if($key == 0) $this->getRow($this->style->itemList['rows']['materialSubHeader'], false, 'currentHeader', $withHeader);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement