I have an array being collect via a form like below:
<select multiple="multiple" name="contractors[]" >
Input code to save the array in the DB.
$options = $_POST['contractors'];
$serializedoptions = serialize($options);
It saves the array in the DB in the format below, but I cannot display it properly. When I pull the entire It shows:
a:4:{i:0;s:28:Contractor1";i:1;s:15:"Contractor2";i:2;s:10:"Contractor3";}
How can I get it to display in a more readable format?
$result = mysql_query("SELECT * FROM form_2 GROUP BY jobname");
echo "<table border='1'>
<tr>
<th><font size='1'>Job Name</th>
<th><font size='1'>Contractors</th>
<th><font size='1'>Notes</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><font size='1'>" . $row['jobname'] . "</font></td>";
echo "<td><font size='1'>" . $row['contractors'] . "</font></td>";
echo "<td><font size='1'>" . $row['notes'] . "</font></td>";
echo "</tr>";
}
echo "</table>";
That which is serialized must be unserialized. Just use the
unserializefunction on the data before working with it. In your case, an array will be returned.http://php.net/manual/en/function.unserialize.php
Other languages can unserialize PHP
serialize()as well if you find supporting code for it. For example, here is one for JavaScript: http://phpjs.org/functions/unserialize/EDIT:
Updating the code you added, you can display it like any other PHP variable once you unserialize the value.