Home > Backend Development > PHP Tutorial > php能不能把MYSQL里的某列的值装入单维数组?解决方案

php能不能把MYSQL里的某列的值装入单维数组?解决方案

WBOY
Release: 2016-06-13 10:12:45
Original
900 people have browsed it

php能不能把MYSQL里的某列的值装入单维数组?
比如表name
  字段
  |
————————————
| | |
id class grade
1 a T

2 b W

3 c Z

如上,例如把字段class这一列,装入一个单维数组!
默认mysql_fetch_array 是把行 载入数组,我现在想把某列载入一个数组

------解决方案--------------------
mysql返回的是二维数组,你可以再封装一下的。
------解决方案--------------------
mysql 函数组没有提供此功能,需要编程解决
PDO 提供了此功能
------解决方案--------------------
你读出列的值,在程序里面给他放到一个单维数组里,供其他地方用呗
------解决方案--------------------
那在你查询的时候,只差一个字段不久行?

PHP code
$sql = "SELECT class FROM name";$result = mysql_query($sql,$this->mysql);while ($arr = mysql_fetch_array($result)){  print_r($arr);}mysql_close();<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template