Search code examples
wordpressfor-loophtml-tabledompdf

I need to create a table on 2 different Page on Dom PDF Using PHP for loop?


I have tried to Create a Table using DOM PDF but uncertainly I got error of syntax token error, Can any body help me to figure out this issue.

Below is my code of for loop which i have used inside the $html variables.

    $html = "<html></head>
    <body>
      <main>
       
                <table>
                <tr>
                    <th '>Year</th>
                    <th '>Age</th>
                    <th  align='center'>Saving</th>
                    <th >Expenses</th>
                </tr>"
                
                for ($year=0; $year < 15; $year++) { 
                    $html.=
                        '<tr class="table_row">
                                <td align="center">'.$year.'</td>
                                <td align="center">'.$table_data['age'][$year].'</td>
                                <td align="center">'.$table_data['savings'][$year].'</td>
                                <td align="center">'.$table_data['expenses'][$year].'</td>
                            </tr>';
                }  
" </table> 
            
      </main>
    </body>
    </html>";

Solution

  • You need to create two pdf & use 2 foreach loops on both pdf to get the data as you need.

    Try this solution. it works for me.