"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Construct PHP Arrays from MySQL Column Data?

How to Construct PHP Arrays from MySQL Column Data?

Published on 2024-11-08
Browse:187

How to Construct PHP Arrays from MySQL Column Data?

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.

Release Statement This article is reprinted at: 1729685263 If ​​there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

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