june_c21 Posted November 15, 2007 Share Posted November 15, 2007 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); } Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/ Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 its probably the SQL statement.. try $query="SELECT user.acc_no, report.staff_no, user.name, report.amount LEFT JOIN report on report.staff_no= user.staff_no FROM user WHERE status ='approve' Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391829 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 MadTechie ,error with your query... Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391833 Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 what was the error ? Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391847 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Web\claim\maybank_report.php on line 62 Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391851 Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 I spotted it (i think) try $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' Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391852 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 Parse error: syntax error, unexpected T_STRING in C:\Web\claim\maybank_report.php on line 59 Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391854 Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 $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'"; add the "; to the end Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391857 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Web\claim\maybank_report.php on line 62 Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391858 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 $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]'" ; the result will repeat 3 times for each row of record Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391863 Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391867 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 ABBBBBBBBABBBBBBBBABBBBBBBBABBBBBBBBABBBBBBBBABBBBBBBBABBBBBBBBABBBBBBBBAAAAABBABBABBABBABAAAAAAAAAAAA sorry to trouble you, hope you can help as i need to complete my assignment today. thanks Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391869 Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 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]'" ; Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391880 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391890 Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391893 Share on other sites More sharing options...
june_c21 Posted November 15, 2007 Author Share Posted November 15, 2007 i must user the first loop else the total won't be display. Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-391968 Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 how is the first loop linked to the total ? Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-392092 Share on other sites More sharing options...
june_c21 Posted November 16, 2007 Author Share Posted November 16, 2007 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(); } } Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-392507 Share on other sites More sharing options...
MadTechie Posted November 16, 2007 Share Posted November 16, 2007 $queryAA="SELECT staff_no from report "; should be $queryAA="SELECT DISTINCT staff_no from report "; Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-392513 Share on other sites More sharing options...
june_c21 Posted November 16, 2007 Author Share Posted November 16, 2007 ya, i just edit it but it didn't appear all the record in the database. why? Quote Link to comment https://forums.phpfreaks.com/topic/77403-repeating/#findComment-392536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.