Jump to content

Help Me To Solve This


june_c21

Recommended Posts

hi,

 

everytime i run this script, the amount column will be zero instead of total sum amount. can someone tell me what's wrong with this code? thanks

 

$query="SELECT user.acc_no, report1.staff_no, user.name FROM user,report1 WHERE report1.staff_no = user.staff_no && user.bank ='Maybank' && report1.month='May' group by staff_no " ;
$result = mysql_query($query,$dblink);
$i=1;
while ($row = mysql_fetch_row($result))
  {
  // $x_pos = $pdf->SetX(50);
  $y_pos = $pdf->GetY();
  $pdf->SetX(30);
  $pdf->Cell(10,6,$i,1,0,'C',1);
  $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,0,'C',0);
$i++;

  $query1 = "SELECT SUM(amount) FROM report1 where staff_no = '$row[1]'and report1.status='approve'and report1.month='May'";
  $result1 = mysql_query($query1, $dblink);
  $myrow1 = mysql_fetch_row($result1);

		$y_pos = $pdf->GetY();
  			$pdf->SetX(210);
  			$pdf->Cell(20,6,(sprintf('%.2f',$myrow1[0])),1,1,'C',0);
  		$pdf->Ln();
}

$query2 = "SELECT SUM(amount) FROM report1,user where report1.status='approve' and user.staff_no=report1.staff_no and bank='Maybank' and report1.month='May' ";
  $result2 = mysql_query($query2, $dblink);
  $myrow2 = mysql_fetch_row($result2);
		$pdf->SetY(200);
  			$pdf->SetX(210);
  			$pdf->Cell(20,6,(sprintf('%.2f',$myrow2[0])),1,1,'C',0);

Link to comment
https://forums.phpfreaks.com/topic/109503-help-me-to-solve-this/
Share on other sites

Am very new here just now... so hi :-).

 

About your code, i presume you are using FPDF. Can you please give more information since I can't tell which is the total sum and how you get it. Also, does the query itself generate the information you need to generate the total?

yeah, i using FPDF

 

the coding to generate the amount is

$query1 = "SELECT SUM(amount) FROM report1 where staff_no = '$row[1]'and report1.status='approve' and report1.month='May'";
  $result1 = mysql_query($query1, $dblink);
  $myrow1 = mysql_fetch_row($result1);

		$y_pos = $pdf->GetY();
  			$pdf->SetX(210);
  			$pdf->Cell(20,6,(sprintf('%.2f',$myrow1[0])),1,1,'C',0);
  		$pdf->Ln();
}

am not really sure if i get you problem right but you may try these:

 

try using number_format() instead of sprintf()

 

number_format($myrow1[0], 2, ',', '.')

 

suggestion:

 

instead of using numerical index for your mysql result, use the associative name as it would be less error prone (wrong column selection) and more readable (since you do not need to check your previous query for the what specific field you are accessing).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.