How can PHP arrays be used to store and manipulate data retrieved from a MySQL query result set?
To store and manipulate data retrieved from a MySQL query result set using PHP arrays, you can fetch the data from the query result and store it in an array. You can then loop through the array to access and manipulate the data as needed.
// Assuming $conn is the MySQL database connection
$query = "SELECT * FROM table_name";
$result = mysqli_query($conn, $query);
$data = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
}
// Manipulate the data stored in the array
foreach ($data as $row) {
echo $row['column_name'] . "<br>";
}
Related questions
-
PHP version checking scalability
-
MySQL VIEWs complex query
-
DateTime strtotime date