您好,欢迎访问一九零五行业门户网

php如何样获取mysql表中所有字段名到一个数组

php怎么样获取mysql表中所有字段名到一个数组?
php怎么样获取mysql表中所有字段名到一个数组?
select * from table 虽然能做到,但是返回的是array('name'=>'hello','age'=>30,...)这样的数组,但我只需要array('name','age');
有其他更快的方法吗?
------最佳解决方案--------------------
首先 用select * from table limit(0,10) 查出所有数据到一个数组,格式为array('name'=>'hello','age'=>30,...),然后对该数组使用array_keys()函数 ,即可得到你要的格式array('name','age',......);
------其他解决方案--------------------
这样写
$result = mysql_query(select * from table);
$fields = mysql_num_fields($result);
for ($i=0; $i < $fields; $i++) {
$names[] = mysql_field_name($result, $i);
}
print_r($names);
------其他解决方案--------------------
select  column_name  from  `information_schema`.`columns`   where `table_schema`='你的书库库名'  and  `table_name`='你的表名'   order by column_name;
改改就能用了
------其他解决方案--------------------
select name,age from table
------其他解决方案--------------------
foreach试试呢
其它类似信息

推荐信息