how to print payslip for each employee using javascript

Hi
I am working on a payroll project and I am coding with php,html,js and mysql on xampp server. I have a salary sheet code which needs to be printed in pdf format for each employee with their names as the pdf filename.
on running the php page the js code triggers automatically and generates pdf files but the problem is the salary data of the first employee is printed on every payslip but
The filename changes with every pdf.
for example :
1st emp name is rajesh rao, 2nd emp name is a.ghosh.
now when I print the sheets, then 2 pdf files are created for these 2 employees with their names as filenames but the salary data is not changing on the 2nd emp sheet/ Any Help will be appreciated

  Salary Sheet         $row = mysqli_fetch_array($myquery, MYSQLI_ASSOC); ?> 
Salary Sheet of :    ,  
Emp-Code
Designation
EARNINGS
Basic
House Rent Allowance
DEDUCTIONS  
Professional Tax
Provident Fund
   
TOTAL PAY : Rs.
?>
jkon 636 Posting Whiz in Training Featured Poster 6 Years Ago

My advice is to start again from the basics , what pdf is , what PHP , what HTML and what JavaScript. You definitely not printing any pdf here and you have mixed PHP logic with view with JavaScript code that uses directly PHP variables.

Ritesh_8 0 Newbie Poster 6 Years Ago

hello jkon,
Thanks for the advice. this code is printing pdf files via pdfcreator app. if you can help put with some ocde snippets then it will be nice. I have found out a way to print with fpdf .I can print a html table with mysql data in pdf format for a single employee with a print button but I want to print all the payslips all at once. I know it can be done but maybe I am missing something in the code which I need help.

Brianbc 9 Light Poster 6 Years Ago
$row = mysqli_fetch_array($myquery, MYSQLI_ASSOC); ?>

You are only accessing one row from the result of your query. And that is all that there will be in pdata. So maybe you should modify to have a loop like this while($row = mysqli_fetch_array($myquery, MYSQLI_ASSOC))<> Then put pdata before that loop so that you can do whatever you are doing for all the rows from your query.

jkon commented: +1 for reading this code and understood it . I have never used msqli (PDO fun here) +9

urtrivedi 276 Nearly a Posting Virtuoso 6 Years Ago

You have to use only one fpdf object for whole process
Loop through alll payslip record
you have already written code for one payslip, so put that code in your above loop
when next record start add page to your fpdf object
output your fpdf object after loop ends javascript has no role in your problem

Facebook Twitter LinkedIn Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Related Topics Not what you need?

Reach out to all the awesome people in our web development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions.