filmov
tv
How to Make PDF Invoices From Database in PHP | PHP FPDF Tutorial #example1

Показать описание
welcome to php fpdf tutorial example videos.
in this example, i will use invoice from first chapter then combine it with database to make a dynamic invoices.
i have prepared some data beforehand using mock data generator.
there are a lot of websites which provides mock data generation for free. Just google "random data generator".
here is the database design i use in this example.
i have a master table for clients, with clientID as the key.
another table for invoice which contain clientID as a foreign key.
and finally, a table for items of each invoices, using invoiceID as the foreign key.
now let's begin.
first let's make a form page, to select which invoice to be generated.
here we need to get lists of invoices from database so lets make a database connection.
in my case, the database is named "invoiceDB".
make a form with "get" method, and "invoice-db dot php" as action, we will make the file later.
make a dropdown select input named invoiceID.
query the invoices id from database.
then show the result as options.
and don't forget to add submit button.
and the form is done.
now let's make the invoice.
to make things easier, just copy the php file from first chapter and rename it to invoice-db dot php.
add a database connection.
then query the invoice data from invoice table in database.
here we need to inner join clients table using clientID.
and use invoiceID received from GET method in where clause.
and don't forget to fetch the result in an array or object, so we can use it.
now lets replace the previous static invoice data with the dynamic data from database.
now lets display the items.
we need to query the item table in database and use invoiceID in where clause.
and make two variables to hold total tax and total amount.
display the items using where loop, replacing the contents.
we can add thousand separator for numbers using number_format function.
and at the end of each loop, accumulate the total tax and total amount.
finally, display the total amount, total tax, and total due.
this conclude this tutorial video.
thank you for watching, and see you in the next video.
in this example, i will use invoice from first chapter then combine it with database to make a dynamic invoices.
i have prepared some data beforehand using mock data generator.
there are a lot of websites which provides mock data generation for free. Just google "random data generator".
here is the database design i use in this example.
i have a master table for clients, with clientID as the key.
another table for invoice which contain clientID as a foreign key.
and finally, a table for items of each invoices, using invoiceID as the foreign key.
now let's begin.
first let's make a form page, to select which invoice to be generated.
here we need to get lists of invoices from database so lets make a database connection.
in my case, the database is named "invoiceDB".
make a form with "get" method, and "invoice-db dot php" as action, we will make the file later.
make a dropdown select input named invoiceID.
query the invoices id from database.
then show the result as options.
and don't forget to add submit button.
and the form is done.
now let's make the invoice.
to make things easier, just copy the php file from first chapter and rename it to invoice-db dot php.
add a database connection.
then query the invoice data from invoice table in database.
here we need to inner join clients table using clientID.
and use invoiceID received from GET method in where clause.
and don't forget to fetch the result in an array or object, so we can use it.
now lets replace the previous static invoice data with the dynamic data from database.
now lets display the items.
we need to query the item table in database and use invoiceID in where clause.
and make two variables to hold total tax and total amount.
display the items using where loop, replacing the contents.
we can add thousand separator for numbers using number_format function.
and at the end of each loop, accumulate the total tax and total amount.
finally, display the total amount, total tax, and total due.
this conclude this tutorial video.
thank you for watching, and see you in the next video.
Комментарии