Jump to content

Problem in table format


newphpbees

Recommended Posts

Hi...

 

Good day!

 

I just want to know how can I change the format of my table. here is my code:

 


<?php
  include 'config.php';
  
  $sql = "SELECT DATE_FORMAT(d.FROM_DATE, '%M %c') AS FROM_DATE, DATE_FORMAT(d.TO_DATE, '%M %c, %Y') AS TO_DATE, g.EMP_NO, g.fullName, g.Rate, g.Reg_Hours, g.Basic_Pay, g.OTReg_Hours, g.SunReg_Hours, g.OTSun_Hours, g.HolReg_Hours, g.HolRegOT_Hours, g.HolLeave_Hours_Tot, SUM(g.NPReg_Hours + g.NPSun_Hours + g.NPHol_Hours) AS NIGHT_PREMIUM, SUM(g.MealReg_Hours + g.MealSun_Hours) AS MEAL_ALLOWANCE, g.Cola_Hours, g.Basic_Pay, g.OTReg_Amt, g.SunReg_Amt, g.OTSun_Amt, g.HolReg_Amt, g.HolRegOT_Amt, g.HolLeave_Amt, g.NP_Amt, g.Meal_Amt, g.Cola_Amt,  p.COMPANY_NAME, p.PERIOD, p.NAME, p.FIRST_LINE, p.RATE_Label, p.EARNINGS, p.HRS, p.AMOUNT, p.BASIC_PAY_Label, p.REGULAR_OVERTIME, p.SUN_SPEC_HOLIDAY, p.SUN_SPEC_HOL_OT, p.REG_HOLIDAY, p.REG_HOLIDAY_OT, p.HOLIDAY_LEAVE, p.NIGHT_PREMIUM_Label, p.MEAL_ALLOWANCE_Label, p.COLA, p.13TH_MONTH, p.SECOND_LINE FROM $PAYROLL.casual_payslip_label p, $PAYROLL.casual_generate_payroll g, $PAYROLL.casual_date_upload d GROUP BY g.EMP_NO"or die(mysql_error());
  $rs_label = $conn2->GetAll($sql);
  
  $smarty->assign('rs_label', $rs_label);
$smarty->display('payslip.tpl');
$smarty->display('casual_payslip.tpl');
?>

<div>
{section name=att loop=$rs_label}
<table class="stat">
<tr>
<td>{$rs_label[att].COMPANY_NAME}</td>
<tr/>

<tr>
<td>{$rs_label[att].PERIOD} {$rs_label[att].FROM_DATE}-{$rs_label[att].TO_DATE}</td>
<tr/>

<tr>
<td>{$rs_label[att].NAME} {$rs_label[att].fullName}</td>
</tr>

<tr>
<td>{$rs_label[att].FIRST_LINE}</td>
</tr>

<tr>
<td>{$rs_label[att].RATE_Label} {$rs_label[att].Rate}</td>
</tr>

<tr>
  <td>{$rs_label[att].EARNINGS}              {$rs_label[att].HRS}     {$rs_label[att].AMOUNT}</td>
</tr>

<tr>
<td>{$rs_label[att].BASIC_PAY_Label}                {$rs_label[att].Reg_Hours}       {$rs_label[att].Basic_Pay}</td>
</tr>

<tr>
<td>{$rs_label[att].REGULAR_OVERTIME}     {$rs_label[att].OTReg_Hours}       {$rs_label[att].OTReg_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].SUN_SPEC_HOLIDAY}     {$rs_label[att].SunReg_Hours}       {$rs_label[att].SunReg_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].SUN_SPEC_HOL_OT}     {$rs_label[att].OTSun_Hours}       {$rs_label[att].OTSun_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].REG_HOLIDAY}            {$rs_label[att].HolReg_Hours}       {$rs_label[att].HolReg_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].REG_HOLIDAY_OT}     {$rs_label[att].HolRegOT_Hours}       {$rs_label[att].HolRegOT_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].HOLIDAY_LEAVE}        {$rs_label[att].HolLeave_Hours_Tot}       {$rs_label[att].HolLeave_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].NIGHT_PREMIUM_Label}       {$rs_label[att].NIGHT_PREMIUM}       {$rs_label[att].NP_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].MEAL_ALLOWANCE_Label}     {$rs_label[att].MEAL_ALLOWANCE}       {$rs_label[att].Meal_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].COLA}{$rs_label[att].Cola_Hours}       {$rs_label[att].Cola_Amt}</td>
</tr>

<tr>
<td>{$rs_label[att].SECOND_LINE}</td>
</tr>
</table>
{/section}
</div>

 

the output of this code:

 

Company Name

Period : jul 09- July 22,2011

Name : Juan Dela Cruz

 

Rate : 339.80

EARNINGS HRS AMOUNT

Basic Pay             91.45 3,884.34

Regular Overtime             0.00 0.00

Sun/Spec Holiday             0.00 0.00

Sun/Spec Hol. OT             0.00 0.00

Reg. Holiday 0.00 0.00

Reg. Holiday OT 0.00 0.00

Holiday/Leave 0.00 0.00

Night Premium 0.00 0.00

Meal Allowance 0.00 0.00

COLA (P28 Allow)             0.00 0.00

13th Month 0.00

 

 

Company Name

Period : jul 09- July 22,2011

Name : Ann Chin

 

Rate : 339.80

EARNINGS HRS AMOUNT

Basic Pay             100.00 4247.5

Regular Overtime             0.00 0.00

Sun/Spec Holiday             0.00 0.00

Sun/Spec Hol. OT             0.00 0.00

Reg. Holiday             0.00 0.00

Reg. Holiday OT             0.00 0.00

Holiday/Leave 0.00 0.00

Night Premium 0.00 0.00

Meal Allowance 0.00 0.00

COLA (P28 Allow)             0.00 0.00

13th Month 0.00

 

 

Company Name

Period : jul 09- July 22,2011

Name : John Lee

 

Rate : 339.80

EARNINGS HRS AMOUNT

Basic Pay             101 4289.96

Regular Overtime             0.00 0.00

Sun/Spec Holiday             0.00 0.00

Sun/Spec Hol. OT             0.00 0.00

Reg. Holiday 0.00 0.00

Reg. Holiday OT 0.00 0.00

Holiday/Leave 0.00 0.00

Night Premium 0.00 0.00

Meal Allowance 0.00 0.00

COLA (P28 Allow)             0.00 0.00

13th Month 0.00

 

 

Company Name

Period : jul 09- July 22,2011

Name : Mary Ann Chan

 

Rate : 339.80

EARNINGS HRS AMOUNT

Basic Pay             90 3,882.75

Regular Overtime             0.00 0.00

Sun/Spec Holiday             0.00 0.00

Sun/Spec Hol. OT             0.00 0.00

Reg. Holiday 0.00 0.00

Reg. Holiday OT 0.00 0.00

Holiday/Leave 0.00 0.00

Night Premium 0.00 0.00

Meal Allowance 0.00 0.00

COLA (P28 Allow)             0.00 0.00

13th Month 0.00

 

I have a lot of employee so the data is long.

 

I attach the format I want to happen.

 

Thank you

 

17584_.doc

Link to comment
Share on other sites

Hi there! I hope I could help with this.

So listen, the number of columns should be equal. So I organised them so the main table will have 2 columns. then in the "rate" row I added an inner table with 3 columns.

 

here's the script:

 

 

 

<table class="stat">

<tr>

<td colspan="2">{$rs_label[att].COMPANY_NAME}</td>

<tr/>

 

<tr>

<td>{$rs_label[att].PERIOD} </td>

<td> {$rs_label[att].FROM_DATE}-{$rs_label[att].TO_DATE}</td>

<tr/>

 

<tr>

<td>{$rs_label[att].NAME} </td>

<td>{$rs_label[att].fullName}</td>

</tr>

 

<tr>

<td colspan="2">{$rs_label[att].FIRST_LINE}</td>

</tr>

 

<tr>

<td>{$rs_label[att].RATE_Label}</td>

<td> {$rs_label[att].Rate}</td>

</tr>

 

 

 

<tr>

<td colspan="2">

<table>

<tr>

<td>{$rs_label[att].EARNINGS}</td>

<td>{$rs_label[att].HRS}</td>

<td>{$rs_label[att].AMOUNT}</td>

</tr>

 

<tr>

<td>{$rs_label[att].BASIC_PAY_Label}</td>

<td>{$rs_label[att].Reg_Hours}</td>

<td>{$rs_label[att].Basic_Pay}</td>

</tr>

 

<tr>

<td>{$rs_label[att].REGULAR_OVERTIME}</td>

<td>{$rs_label[att].OTReg_Hours}</td>

<td>{$rs_label[att].OTReg_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].SUN_SPEC_HOLIDAY}</td>

<td>{$rs_label[att].SunReg_Hours}</td>

<td>{$rs_label[att].SunReg_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].SUN_SPEC_HOL_OT}</td>

<td>{$rs_label[att].OTSun_Hours}</td>

<td>{$rs_label[att].OTSun_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].REG_HOLIDAY}</td>

<td>{$rs_label[att].HolReg_Hours}</td>

<td>{$rs_label[att].HolReg_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].REG_HOLIDAY_OT}</td>

<td>{$rs_label[att].HolRegOT_Hours}</td>

<td>{$rs_label[att].HolRegOT_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].HOLIDAY_LEAVE}</td>

<td>{$rs_label[att].HolLeave_Hours_Tot}</td>

<td>{$rs_label[att].HolLeave_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].NIGHT_PREMIUM_Label}</td>

<td>{$rs_label[att].NIGHT_PREMIUM}</td>

<td>{$rs_label[att].NP_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].MEAL_ALLOWANCE_Label}</td>

<td>{$rs_label[att].MEAL_ALLOWANCE}</td>

<td>{$rs_label[att].Meal_Amt}</td>

</tr>

 

<tr>

<td>{$rs_label[att].COLA}{$rs_label[att].Cola_Hours}</td>

<td>{$rs_label[att].Cola_Amt}</td>

<td></td>

</tr>

 

<tr>

<td colspan="3">{$rs_label[att].SECOND_LINE}</td>

</tr>

 

</table>

</td>

</tr>

 

</table>

 

Please tell me how it turned out because I can't test it without the database and all :)

Link to comment
Share on other sites

I try your suggested code and still it was one line but i really appreciate your help..

 

Actually i already revised my code to change the design but still it was one side or one line.

 

here is my code:

 

<div>
{section name=att loop=$rs_label}
<table class="stat" border = "0" width="auto">
<tr>
<td colspan="6" align="center"><b>{$rs_label[att].COMPANY_NAME}</b></td>
<tr/>

<tr>
<td colspan="3" align="center"><b>{$rs_label[att].fullName}</b></td> <td colspan="3" align="center"><b>{$rs_label[att].Rate}</b></td>
</tr>

<tr>
<td colspan="3"><b>{$rs_label[att].PERIOD} {$rs_label[att].FROM_DATE}-{$rs_label[att].TO_DATE}</b></td> <td colspan="3" align="center"><b>{$rs_label[att].RATE_Label}</b></td>   
<tr/>

<tr>
<td colspan="3"><b>{$rs_label[att].EARNINGS}</b></td> <td colspan="3"><b>{$rs_label[att].DEDUCTIONS_Label}</b></td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right">{$rs_label[att].HRS}</td><td colspan="1" align="right">{$rs_label[att].AMOUNT}</td><td colspan="1"></td><td colspan="1" align="right">{$rs_label[att].HRS}</td><td colspan="1" align="right">{$rs_label[att].AMOUNT}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].BASIC_PAY_Label}</td><td colspan="1" align="right">{$rs_label[att].Reg_Hours}</td><td colspan="1" align="right">{$rs_label[att].Basic_Pay}</td><td colspan="1">{$rs_label[att].Late_Label}</td><td colspan="1" align="right">{$rs_label[att].Late_Hours}</td><td colspan="1" align="right">{$rs_label[att].Late}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].REGULAR_OVERTIME}</td><td colspan="1" align="right">{$rs_label[att].OTReg_Hours}</td><td colspan="1" align="right">{$rs_label[att].OTReg_Amt}</td><td colspan="1">{$rs_label[att].WITHHOLDING_TAX_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].TAX}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].SUN_SPEC_HOLIDAY}</td><td colspan="1" align="right">{$rs_label[att].SunReg_Hours}</td><td colspan="1" align="right">{$rs_label[att].SunReg_Amt}</td><td colspan="1">{$rs_label[att].SSS_CONTRIBUTION_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].SSS}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].SUN_SPEC_HOL_OT}</td><td colspan="1" align="right">{$rs_label[att].OTSun_Hours}</td><td colspan="1" align="right">{$rs_label[att].OTSun_Amt}</td><td colspan="1">{$rs_label[att].MEDICARE_CONT_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].PCHL}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].REG_HOLIDAY}</td><td colspan="1" align="right">{$rs_label[att].HolReg_Hours}</td><td colspan="1" align="right">{$rs_label[att].HolReg_Amt}</td><td colspan="1">{$rs_label[att].HDMF_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].HDMF}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].REG_HOLIDAY_OT}</td><td colspan="1" align="right">{$rs_label[att].HolRegOT_Hours}</td><td colspan="1" align="right">{$rs_label[att].HolRegOT_Amt}</td><td colspan="1">{$rs_label[att].SSS_Loan_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].SSS_Amor}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].HOLIDAY_LEAVE}</td><td colspan="1" align="right">{$rs_label[att].HolLeave_Hours_Tot}</td><td colspan="1" align="right">{$rs_label[att].HolLeave_Amt}</td><td colspan="1">{$rs_label[att].HDMF_Loan_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].HDMF_Amor}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].NIGHT_PREMIUM_Label}</td><td colspan="1" align="right">{$rs_label[att].NIGHT_PREMIUM}</td><td colspan="1" align="right">{$rs_label[att].NP_Amt}</td><td colspan="1">{$rs_label[att].TAX_ADJT_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].TaxAjt}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].MEAL_ALLOWANCE_Label}</td><td colspan="1" align="right">{$rs_label[att].MEAL_ALLOWANCE}</td><td colspan="1" align="right">{$rs_label[att].Meal_Amt}</td><td colspan="1">{$rs_label[att].Cash_Advance_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].CashAdvance}</td>
</tr>

<tr>
<td colspan="1">{$rs_label[att].COLA}</td><td colspan="1" align="right">{$rs_label[att].Cola_Hours}</td><td colspan="1" align="right">{$rs_label[att].Cola_Amt}</td><td colspan="1">{$rs_label[att].Advances_Shirt_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].AdvanceShirt}</td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td><td colspan="1">{$rs_label[att].Advances_Medical_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].AdvanceMed}</td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td><td colspan="1">{$rs_label[att].Advances_Others_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].AdvanceOther}</td>
</tr>


<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td><td colspan="1">{$rs_label[att].CANTEEN_Label}</td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].Canteen}</td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].LINE_Label}</td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].LINE_Label}</td>
</tr>

<tr>
<td colspan="1"><b>{$rs_label[att].TOTAL_EARNINGS_Label}</b></td><td colspan="1" align="right"></td><td colspan="1" align="right"><b>{$rs_label[att].TotalEarnings}</b></td><td colspan="1"><b>{$rs_label[att].TOTAL_DEDUCTIONS_Label}</b></td><td colspan="1" align="right"></td><td colspan="1" align="right"><b>{$rs_label[att].TotalDeductions}</b></td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="3" align="center">{$rs_label[att].Receipt_Pay}</td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>
<tr>
<td colspan="3" align="center">{$rs_label[att].Receipt_Detail}</td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="3" align="center">{$rs_label[att].Receipt_Detail1}</td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="3" align="center">{$rs_label[att].Receipt_Detail2}</td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="3" align="center">{$rs_label[att].fullName}</td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="3" align="center">{$rs_label[att].FIRST_LINE}</td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td>
</tr>

<tr>
<td colspan="3" align="center">{$rs_label[att].SIGNATURE}</td><td colspan="1"><b>{$rs_label[att].TAKE_HOME_PAY_Label}</b></td><td colspan="1" align="right"></td><td colspan="1" align="right"><b>{$rs_label[att].TakeHomePay}</b></td>
</tr>

<tr>
<td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right"></td><td colspan="1"></td><td colspan="1" align="right"></td><td colspan="1" align="right">{$rs_label[att].SECOND_LINE}</td>
</tr>

<tr>
<td colspan="6">{$rs_label[att].FOURTH_LINE}</td>
</tr>

</table>

{/section}
</div>
[code]
I want is like this
Payslip Employee 1    	Payslip Employee 2	Payslip Employee 3
List of data1         	List of data 2        	List of data 3 a

And so on…


Now the result of my code is :

Payslip Employee 1
List of data1

Payslip Employee 2
List of data2
   
Payslip Employee 3
List of data3

Payslip Employee 4
List of data4

Payslip Employee 5
List of data5

Payslip Employee 6
List of data6

Thank you

Link to comment
Share on other sites

oh sorry, I didn't realize you wanted the results to be populated in columns.

I don't know php well. but I could tell you my idea.

 

i guess that {section} is the part where the loop runs

 

so before {section} you define a variable, for example, count and assign it a value 0

and add a main table

 

var $count=0;

<table>

 

//then add your {section} line

 

{section name=att loop=$rs_label}

 

if( $count==0)//if count =0 then start a new row

{

<tr>

}

<td>

//inside this td tag put your table of class "stat"

<table class="stat" border = "0" width="auto">

/* put the rest of your table here*/

</table>

<td>

 

//then add 1 to count

$count++;

//check if count reached 3 , which is the number of columns you want, then reset to 0

 

if($count==3)

{

$count=0;

//now close the row tag which is </tr>

</tr>

}

 

//now close your section then your table tag

 

 

{/section}

</table>

 

 

I hope this will help. As I said, I don't know php well, but I think I got the variable declaration correct. Anyway, double check my php syntax and tell me how it went.

 

Good luck!  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.