Jump to content

Repeating


june_c21

Recommended Posts

hi, how come my output is repeating with this code? what's wrong? Please help. thanks

 

$queryAA="SELECT staff_no from report ";

$resultAA = mysql_query($queryAA,$dblink);

while($rowAA = mysql_fetch_row($resultAA))

{

$query="SELECT user.acc_no, report.staff_no, user.name, report.amount FROM user,report WHERE report.staff_no = user.staff_no and status ='approve' and user.bank ='Maybank' and report.staff_no = '$rowAA[0]' " ;

// echo $query;

$result = mysql_query($query,$dblink);

while($row = mysql_fetch_row($result))

  {

  // $x_pos = $pdf->SetX(50);

  $y_pos = $pdf->GetY();

  $pdf->SetX(40);

  $pdf->Cell(50,6,$row[0],1,0,'C',1);

  $pdf->SetX(90);

  $pdf->Cell(40,6,$row[1],1,0,'C',0);

  $pdf->SetX(130);

  $pdf->Cell(80,6,$row[2],1,0,'C',0);

  $pdf->SetX(210);

  $pdf->Cell(20,6,$row[3],1,1,'C',0);

 

}

Link to comment
Share on other sites

run this and tell me how many rows you have and the also post the A's and B's echo'd

 

its kinda hard you workout the problem without knowing the database

 

$queryAA="SELECT staff_no from report ";
$resultAA = mysql_query($queryAA,$dblink);
while($rowAA = mysql_fetch_row($resultAA))
{
echo "A";
$query="SELECT user.acc_no, report.staff_no, user.name, report.amount FROM user LEFT JOIN report on report.staff_no= user.staff_no WHERE status ='approve'and user.bank='maybank'and user.staff_no= '$rowAA[0]'" ;
// echo $query;
$result = mysql_query($query,$dblink);
while($row = mysql_fetch_row($result))
  {
echo "B";
  // $x_pos = $pdf->SetX(50);
  $y_pos = $pdf->GetY();
  $pdf->SetX(40);
  $pdf->Cell(50,6,$row[0],1,0,'C',1);
  $pdf->SetX(90);
  $pdf->Cell(40,6,$row[1],1,0,'C',0);
  $pdf->SetX(130);
  $pdf->Cell(80,6,$row[2],1,0,'C',0);
  $pdf->SetX(210);
  $pdf->Cell(20,6,$row[3],1,1,'C',0);

}[code]

[/code]

Link to comment
Share on other sites

do you have a database sceama and some sample data..?

 

other than that i would have to guess

 

$query="SELECT DISTINCT  user.acc_no, report.staff_no, user.name, report.amount FROM user LEFT JOIN report on report.staff_no= user.staff_no WHERE status ='approve'and user.bank='maybank'and user.staff_no= '$rowAA[0]'" ;

Link to comment
Share on other sites

Account Number                      Staff No                        Name                      Amount                    Total

1234567890                                A                                Ali                            20 

1234567890                                A                                Ali                            10

1234567890                                A                                Ali                            15                            45

 

1234567890                                A                                Ali                            20 

1234567890                                A                                Ali                            10

1234567890                                A                                Ali                            15                            45

 

1234567890                                A                                Ali                            20 

1234567890                                A                                Ali                            10

1234567890                                A                                Ali                            15                            45

 

 

this is the repeat result.

Link to comment
Share on other sites

looks like the first loop isn't needed

 


$query="SELECT user.acc_no, report.staff_no, user.name, report.amount FROM user LEFT JOIN report on report.staff_no= user.staff_no WHERE status ='approve'and user.bank='maybank' " ;
// echo $query;
$result = mysql_query($query,$dblink);
while($row = mysql_fetch_row($result))
  {
  // $x_pos = $pdf->SetX(50);
  $y_pos = $pdf->GetY();
  $pdf->SetX(40);
  $pdf->Cell(50,6,$row[0],1,0,'C',1);
  $pdf->SetX(90);
  $pdf->Cell(40,6,$row[1],1,0,'C',0);
  $pdf->SetX(130);
  $pdf->Cell(80,6,$row[2],1,0,'C',0);
  $pdf->SetX(210);
  $pdf->Cell(20,6,$row[3],1,1,'C',0);

}

 

NOTE: your need to remove the next } below the last one in the posted code

Link to comment
Share on other sites

this is the complete code ....

 

$queryAA="SELECT staff_no from report ";

$resultAA = mysql_query($queryAA,$dblink);

while($rowAA = mysql_fetch_row($resultAA))

{

$query="SELECT report.staff_no, user.name, report.details,report.amount FROM user,report WHERE report.staff_no = user.staff_no and status ='approve' and user.bank ='Maybank' and report.staff_no = '$rowAA[0]' " ;

// echo $query;

$result = mysql_query($query,$dblink);

while($row = mysql_fetch_array($result))

  {

  // $x_pos = $pdf->SetX(50);

  $y_pos = $pdf->GetY();

  $pdf->SetX(40);

  $pdf->Cell(50,6,$row[0],1,0,'C',1);

  $pdf->SetX(90);

  $pdf->Cell(40,6,$row[1],1,0,'C',0);

  $pdf->SetX(130);

  $pdf->Cell(80,6,$row[2],1,0,'C',0);

  $pdf->SetX(210);

  $pdf->Cell(20,6,$row[3],1,1,'C',0);

}

 

  $query1 = "SELECT SUM(amount) FROM report where staff_no = '$rowAA[0]'and report.status='approve'";

  $result1 = mysql_query($query1, $dblink);

  $myrow1 = mysql_fetch_row($result1);

{

  $pdf->SetX(230);

  $pdf->Cell(20,6,$myrow1[0],1,'C',0);

  $pdf->Ln();

}

}

 

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.