I have a form I’ve built in PHP and storing the form field values upon submission by the user in a MySQL database. The form is extremely long and may change periodically. So I used the json_encode functionality to store all the form values into the database. Now I need pull that info out of the database and print it out in the key/value relationship.
So for example, in the database, here’s the row named “json_payload” with some example values in this format:
{"last_name":"Smith","first_name":"John","middle_name":"Doe"..."phone_number":"111.222.3333"}
I need to figure out how to loop through this row in the database and print out all the key/value relationships with PHP in a table format so the above example would end up looking like so:
<table>
<tr>
<td>Last Name</td>
<td>Smith</td>
</tr>
<tr>
<td>First Name</td>
<td>John</td>
</tr>
<tr>
<td>Middle Name</td>
<td>Doe</td>
</tr>
...
<tr>
<td>Phone Number</td>
<td>111.222.3333</td>
</tr>
</table>
JSON is normally used for Javascript/AJAX; in PHP, it’s preferred to use serialize() and unserialize(). But JSON will still work; just decode with json_decode() and loop through the array, outputting your markup: