Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: please help

  1. #1
    New Coder
    Join Date
    Jul 2007
    Location
    Masai, Johor, Malaysia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    please help

    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

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,077
    Thanks
    2
    Thanked 320 Times in 312 Posts
    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) -
    PHP 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() loop 
    If you post your existing code, someone could provide more specific code to accomplish this.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Jul 2007
    Location
    Masai, Johor, Malaysia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    another help

    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>

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    please put your code inside the php tags or the code tags

  • #5
    New Coder
    Join Date
    Jul 2007
    Location
    Masai, Johor, Malaysia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    okay,sorry for the trouble..please help me..

    PHP Code:
    <?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>

  • #6
    New to the CF scene
    Join Date
    Jul 2007
    Location
    Pilipinas
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by NiZAM View Post
    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?

  • #7
    New Coder
    Join Date
    Jul 2007
    Location
    Masai, Johor, Malaysia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    display in-line

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •