While sending data to the database, I used serialize to save arrays in a column. while fetching it to the frontend, I used fetch_all(MYSQLI_ASSOC), it fetched all the data, how can I unserialize that everything in that column before sending it to frontend? My table has many rows.
$result = mysqli_query($this->con, "SELECT * from messages_tb WHERE sender_username= '$sender'");
if ($result) {
$sendThis=$result->fetch_all(MYSQLI_ASSOC);
echo"data:".json_encode($sendThis)."
";
flush();
}
In the messages_tb, I have a column called files, I serialized this column when sending data to the database, how can I specifically unserialize it, yet send the whole result to the frontend, using "while" with "fetch_array", will split my columns and I have to start pushing it one after the other
Use a loop to unserialize the column in the array.
foreach ($sendThis as &$row) {
$row['files'] = unserialize($row['files']);
}
The &
before $row
makes it a reference variable, so modifying the variable updates the array element.