Constructing PHP Arrays from MySQL Column Data
Retrieving data from a MySQL column using mysql_fetch_array results in an array representing a single row. To create an array consisting of values from all rows in a specific column, an effective approach involves iterating through the array and assembling a new array:
$column = array();
while ($row = mysql_fetch_array($info)) {
$column[] = $row[$key]; // Append the value of the column being accessed to the new array
}
By incrementally adding values from each row to the $column array, you can create an array that encompasses the entire column's data. Remember to specify the appropriate $key to indicate the column from which you want to extract values.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3