How to display filter data in php in a proper manner
<p>I want to display my data in a professional way that shorten the code length and look like professional.I didn't want to repeat the code.</p>

<p>Below I have paste my code. plz help me if any body has any best idea.</p>

<pre><code>&lt;table&gt;
&lt;?php if(!empty($labour) || !empty($machines) || !empty($materials) || !empty($contractors)){?&gt;
    &lt;tr&gt;
        &lt;th&gt;Id&lt;/th&gt;
        &lt;th&gt;Name&lt;/th&gt;
        &lt;th&gt;amount_paid&lt;/th&gt;
        &lt;th&gt;date&lt;/th&gt;
    &lt;/tr&gt;
&lt;?php }?&gt;
&lt;?php if(!empty($labour)){  

    $i=1; foreach($labour as $res):?&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $i;?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['LabourCashcredit']['name'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['LabourCashcredit']['amount_paid'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['LabourCashcredit']['date'];?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php $i++; endforeach; 
}?&gt;


&lt;?php if(!empty($machines)){ 
    $i=1; foreach($machines as $res):?&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $i;?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['MachinePayment']['first_name'].' '. $res['MachinePayment']['last_name'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['MachinePayment']['amount_paid'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['MachinePayment']['date'];?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php $i++; endforeach; 
} ?&gt;

&lt;?php if(!empty($materials)){ 
    $i=1; foreach($materials as $res):?&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $i;?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['MaterialPayment']['first_name'].' '. $res['MaterialPayment']['last_name'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['MaterialPayment']['paid_amount'];?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $res['MaterialPayment']['date'];?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php $i++; endforeach; 
} ?&gt;
</code></pre>
