Looking for guidance on MySQL tables and columns issue

Looking for guidance on MySQL tables and columns issue

This is an image of data that I need to use to fill an HTML template that will then be used to create a pdf doc using the docpdf lib. I am querying this in MySQL using the following statement:

As you can see the ‘name’ column has values like VehVin6, VehVin etc.,… and the ‘data’ column has the actual info that I need to fill in the HTML template fields that correspond to the ‘name’ column data.

my question is…

Is it easier to make a PHP code that will make a MySQL connection and then fetch each ‘data’ value from this query using the 'form_field_id" and matching it for what the form field is in the HTML template that needs to be replaced?

Or is it better to create a table called finaldetails, create columns for each value in the ‘name’ column and then somehow assign the values in the ‘data’ column of this query to the associated column and then fetch that data?

Here is the project scenario, each customer is provided with a reference code when they submit a “finaldetails” form (redacted). After processing payment for their service the will see the “instruct” page (redacted) where they will be asked to input that reference_code. If you move to the very bottom of this page there is a list of yellow buttons, one of which has the words “Application For Texas Title” at the very bottom. This is the HTML template (redacted) that I am working with and I want to push the MySQL data to using PHP code. I have a PHP code file created, but as you can tell it is in need of proper coding to complete this process successfully. This is a copy of the PHP code structure thus far that is connected to the link button. It is a work in progress of course


I’ve been working to understand how I can take information that the database can produce in a query and find the best way to structure my request in PHP so that it accomplishes my customers need for a preprepared pdf form that will be downloaded, printed or saved.

As I have said, a reference_code is issued per customer that has a ‘form_id’ associated with it in a ‘forms’ table. My overall thought was to perform a query using the ‘reference_code’ from "forms’ table like such:


And then just get some help with creating code that will take the info in the ‘data’ column that would associate each value with a field name in the template so that the field names are replaced with the data.

So then, of course, the question arose. Would it be easier to create a table with the info and use the existing PHP code to fill the HTML template as such


To me, the latter would seem best, but as I’ve said, I don’t know how to go about it or if it is even possible.

Guidance on this would be of great help. If you could please give me your perspective and an overview of what needs to be done. I can try to put it together and present it for further review