Welcome Guest, Not a member yet? Register   Sign In
Chronological order of data base on the date
#8

(12-05-2018, 12:42 PM)jreklund Wrote: @jelz2018: You added a fair amount of code, it can take time to solve. Your problem resides here. You are first printing your row, checking if it's a new page 18/37 and printing the row again. Before ending the loop and getting a new row.

PHP Code:
   $i 0;
 
   foreach ($rows as $row)
 
   {
 
   
        $number_character 
strlen$row->designation.$row->salary.$row->salary.
 
                           $row->office_entity.$row->lwop.$row->separation_date.$row->separation_cause );
 
       
        $html 
.='<tr>
                <td align="center">'
.$row->date_from.'</td>
                <td align="center">'
.$row->date_to.'</td>
                <td align="left">'
.$row->designation.'</td>
                <td align="left">'
.$row->status.'</td>
                <td align="right">'
.$row->salary.'</td>
                <td align="left">'
.$row->office_entity.'</td>
                <td align="left">'
.$row->lwop.'</td>
                <td align="left">'
.$row->separation_date.'</td>
                <td align="left" style="font-size:7">'
.$row->separation_cause.'</td>
              </tr>'
;
 
         
        
// Second page
 
         if $i == 18)
 
       {
 
           $html .='</table>'// close the table
 
           $html .='<pagebreak />'.$service;
 
           
            $html 
.='<tr>
                <td align="center">'
.$row->date_from.'</td>
                <td align="center">'
.$row->date_to.'</td>
                <td align="left">'
.$row->designation.'</td>
                <td align="left">'
.$row->status.'</td>
                <td align="right">'
.$row->salary.'</td>
                <td align="left">'
.$row->office_entity.'</td>
                <td align="left">'
.$row->lwop.'</td>
                <td align="left">'
.$row->separation_date.'</td>
                <td align="left">'
.$row->separation_cause.'</td>
              </tr>'
;
 
           
        
}
 
       
        
// If there is third page
 
       if $i == 37)
 
       {
 
           $html .='</table>'// close the table
 
           $html .='<pagebreak />'.$service;
 
           
            $html 
.='<tr>
                <td align="center">'
.$row->date_from.'</td>
                <td align="center">'
.$row->date_to.'</td>
                <td align="left">'
.$row->designation.'</td>
                <td align="left">'
.$row->status.'</td>
                <td align="right">'
.$row->salary.'</td>
                <td align="left">'
.$row->office_entity.'</td>
                <td align="left">'
.$row->lwop.'</td>
                <td align="left">'
.$row->separation_date.'</td>
                <td align="left">'
.$row->separation_cause.'</td>
              </tr>'
;
 
           
        
}
 
   
        $i
++;  
    
    


It can be solved dynamically by this, as it's the best solution. Or you just can delete your <tr><td>... inside your if statements. This code checks and recounts $i after 19, so after 18 $i will think it's 0 again and start over. This way you can have hundreds of pages and not worry about adding if( $i == 341 ).

PHP Code:
$i 0
foreach (
$rows as $row)
{

    
$number_character strlen$row->designation.$row->salary.$row->salary.
                        
$row->office_entity.$row->lwop.$row->separation_date.$row->separation_cause );
    
    
$html .='<tr>
            <td align="center">'
.$row->date_from.'</td>
            <td align="center">'
.$row->date_to.'</td>
            <td align="left">'
.$row->designation.'</td>
            <td align="left">'
.$row->status.'</td>
            <td align="right">'
.$row->salary.'</td>
            <td align="left">'
.$row->office_entity.'</td>
            <td align="left">'
.$row->lwop.'</td>
            <td align="left">'
.$row->separation_date.'</td>
            <td align="left" style="font-size:7">'
.$row->separation_cause.'</td>
          </tr>'
;
         
 
    
if( $i++%19 == 18 )
    {
        
$html .='</table>'// close the table
        
$html .='<pagebreak />'.$service;
    }


You should however count $rows and add a check to if( $i++%19 == 18 ), so that it won't print on the last item. So that you don't get an empty page. That can be your homework. :-)

Wow. Thanks for your generous heart for helping me. It's highly appreciated. Thanks a lot.
Reply


Messages In This Thread
RE: Chronological order of data base on the date - by jelz2018 - 12-05-2018, 11:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB