...

View Full Version : please help



NiZAM
07-19-2007, 03:15 AM
I want the output to be like this:

no Emp No Name Ot1 Ot2 Ot3 Ot4 Ot5
1 2006 Sazali Marzuki 241.56 628.46
2 2027 Burham Tarsiwan 252.55 134.69 134.69 151.53
3 2043 Mutan Palanisamy 23 245.38 368.08
4 2141 Ramli Marlan 202.04


but what i get is this:

no Emp No Name Ot1 Ot2 Ot3 Ot4 Ot5
1 2006 Sazali Marzuki 628.46
2 2006 Sazali Marzuki 241.56
3 2027 Burham Tarsiwan 151.53
4 2027 Burham Tarsiwan 134.69
5 2027 Burham Tarsiwan 134.69
6 2027 Burham Tarsiwan 252.55
7 2043 Mutan Palanisamy 245.38
8 2043 Mutan Palanisamy 368.08
9 2043 Mutan Palanisamy 23
10 2141 Ramli Marlan 202.04


can anyone help me how to make the correct script..TQ

CFMaBiSmAd
07-19-2007, 03:33 AM
You need to use a variable to store/remember the value that is the same between rows of data and then only start a new output row when there is a difference between the saved value and the new value.

Assuming that your code uses $row['name'] for the name data, the code would look something like this (untested pseudo code) -

$last_value = ''; // create variable and initialize it to an empty string
while($row=mysql_fetch_assoc($result))
{
if($row['name'] != $last_value)
{
// put your code to output the "no Emp No Name" values here
$last_value = $row['name']; // save the new name as the last_value
} // end of if() statement

// put your code to output any "Ot1 Ot2 Ot3 Ot4 Ot5" values here

} // end of while() loopIf you post your existing code, someone could provide more specific code to accomplish this.

NiZAM
07-19-2007, 03:07 PM
please help me repair this loop..

<?php
$var_i=1;
$EE1 = " "; $EE2= " ";
$T_OT1=0; $T_OT2=0; $T_OT3=0; $T_OT4=0; $T_OT5=0;
$OT1=0; $OT2=0; $OT3=0; $OT4=0; $OT5=0;
while (!$rs_hptrx->EOF) {

$TT = $rs_hptrx->Fields('TRX_CODE');
$AMT = $rs_hptrx->Fields('tot_ot');
$T_AMT = $T_AMT + $rs_hptrx->Fields('tot_ot');

if ( $TT == 'OT1' ) {$OT1 = $AMT; $T_OT1 = $T_OT1 + $AMT;}
else if ( $TT == 'OT2' ) {$OT2 = $AMT; $T_OT2 = $T_OT2 + $AMT;}
else if ( $TT == 'OT3' ) {$OT3 = $AMT; $T_OT3 = $T_OT3 + $AMT;}
else if ( $TT == 'OT4' ) {$OT4 = $AMT; $T_OT4 = $T_OT4 + $AMT;}
else if ( $TT == 'OT5' ) {$OT5 = $AMT; $T_OT5 = $T_OT5 + $AMT;}

$var_i3++;

if (!($EE1 != $EE2)){

?>
<tr class="12">
<td width="3%"><?php echo $var_i ?></td>
<td width="15%" height="46" ><?php echo $rs_hptrx->Fields('emp_Id'); ?></td>
<td width="16%"><?php echo $rs_hptrx->Fields('emp_Name'); ?></td>
<td width="16%"><?php echo $OT1; ?></td>
<td width="7%"><?php echo $OT2; ?></td>
<td width="7%"><?php echo $OT3; ?></td>
<td width="7%"><?php echo $OT4; ?></td>
<td width="7%"><?php echo $OT5; ?></td>
<td width="13%"><?php echo $T_AMT; ?></td>
</tr>
<?php
//$T_AMT = 0;
$var_i++;
$EE1 = $rs_hptrx->Fields('emp_Id');

//$OT1=0; $OT2=0; $OT3=0; $OT4=0; $OT5=0;
}
$rs_hptrx->MoveNext();

$EE2 = $rs_hptrx->Fields('emp_Id');

} // while not eof rs_hptrx
?>

<tr class="">
<td height="2" colspan="1" ></td>
</tr>
<tr class="12">
<td width="3%"><?php echo $var_i -1 ?></td>
<td height="16" colspan="2" >GRAND TOTAL </td>
<td width="7%"><?php echo $T_OT1; ?></td>
<td width="7%"><?php echo $T_OT2; ?></td>
<td width="7%"><?php echo $T_OT3; ?></td>
<td width="7%"><?php echo $T_OT4; ?></td>
<td width="7%"><?php echo $T_OT5; ?></td>
<td width="13%"></td>
</tr>

rafiki
07-19-2007, 10:21 PM
please put your code inside the php tags or the code tags

NiZAM
07-20-2007, 02:16 AM
<?php
$var_i=1;
$EE1 = " "; $EE2= " ";
$T_OT1=0; $T_OT2=0; $T_OT3=0; $T_OT4=0; $T_OT5=0;
$OT1=0; $OT2=0; $OT3=0; $OT4=0; $OT5=0;
while (!$rs_hptrx->EOF) {

$TT = $rs_hptrx->Fields('TRX_CODE');
$AMT = $rs_hptrx->Fields('tot_ot');
$T_AMT = $T_AMT + $rs_hptrx->Fields('tot_ot');

if ( $TT == 'OT1' ) {$OT1 = $AMT; $T_OT1 = $T_OT1 + $AMT;}
else if ( $TT == 'OT2' ) {$OT2 = $AMT; $T_OT2 = $T_OT2 + $AMT;}
else if ( $TT == 'OT3' ) {$OT3 = $AMT; $T_OT3 = $T_OT3 + $AMT;}
else if ( $TT == 'OT4' ) {$OT4 = $AMT; $T_OT4 = $T_OT4 + $AMT;}
else if ( $TT == 'OT5' ) {$OT5 = $AMT; $T_OT5 = $T_OT5 + $AMT;}

$var_i3++;

if (!($EE1 != $EE2)){

?>
<tr class="12">
<td width="3%"><?php echo $var_i ?></td>
<td width="15%" height="46" ><?php echo $rs_hptrx->Fields('emp_Id'); ?></td>
<td width="16%"><?php echo $rs_hptrx->Fields('emp_Name'); ?></td>
<td width="16%"><?php echo $OT1; ?></td>
<td width="7%"><?php echo $OT2; ?></td>
<td width="7%"><?php echo $OT3; ?></td>
<td width="7%"><?php echo $OT4; ?></td>
<td width="7%"><?php echo $OT5; ?></td>
<td width="13%"><?php echo $T_AMT; ?></td>
</tr>
<?php
//$T_AMT = 0;
$var_i++;
$EE1 = $rs_hptrx->Fields('emp_Id');

//$OT1=0; $OT2=0; $OT3=0; $OT4=0; $OT5=0;
}
$rs_hptrx->MoveNext();

$EE2 = $rs_hptrx->Fields('emp_Id');

} // while not eof rs_hptrx
?>

<tr class="">
<td height="2" colspan="1" ></td>
</tr>
<tr class="12">
<td width="3%"><?php echo $var_i -1 ?></td>
<td height="16" colspan="2" >GRAND TOTAL </td>
<td width="7%"><?php echo $T_OT1; ?></td>
<td width="7%"><?php echo $T_OT2; ?></td>
<td width="7%"><?php echo $T_OT3; ?></td>
<td width="7%"><?php echo $T_OT4; ?></td>
<td width="7%"><?php echo $T_OT5; ?></td>
<td width="13%"></td>
</tr>

RavCai-16
07-20-2007, 08:52 AM
I want the output to be like this:

no Emp No Name Ot1 Ot2 Ot3 Ot4 Ot5
1 2006 Sazali Marzuki 241.56 628.46
2 2027 Burham Tarsiwan 252.55 134.69 134.69 151.53
3 2043 Mutan Palanisamy 23 245.38 368.08
4 2141 Ramli Marlan 202.04


but what i get is this:

no Emp No Name Ot1 Ot2 Ot3 Ot4 Ot5
1 2006 Sazali Marzuki 628.46
2 2006 Sazali Marzuki 241.56
3 2027 Burham Tarsiwan 151.53
4 2027 Burham Tarsiwan 134.69
5 2027 Burham Tarsiwan 134.69
6 2027 Burham Tarsiwan 252.55
7 2043 Mutan Palanisamy 245.38
8 2043 Mutan Palanisamy 368.08
9 2043 Mutan Palanisamy 23
10 2141 Ramli Marlan 202.04


can anyone help me how to make the correct script..TQ

I don't know if I get it right,

what are you trying to do?

do you want to SORT it?

are the data coming from an array?

NiZAM
07-20-2007, 10:20 AM
actually i want to display the data in one line for each employee.the data comes from HPTRX table database. i have include the code. it can display it in line but there was something wrong with the looping. i need some help to correct the loops.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum