问题描述
你好!
我想创建一个输入是mySQL
查询结果的函数。
输出应该完全相同,只是不是mySQL结果数组,
但是''真''数组。
所以它也应该得到字段名由mySQL返回并使用那些作为
键。
我无法正常工作:它应该返回
多维数组,
喜欢
$ result_array [1] =数组(
[field1] => field1 value ,
[field2] => field2值,
等
)
莫名其妙我的结果是(代码如下)
$ result_array [1] =数组(
[0] => field1 value,
[field1] => field1值,
[1] => field2值,
[field2] => field2值,
等
)
希望有人可以帮我这个。
Frizzle。
+++++代码++++++
$ get_res = mysql_query(QUERY);
if($ res = mysql_fetch_array ($ get_res))
{
do {
$ result [] = $ res;
} while($ res = mysql_fetch_array($ get_res));
};
foreach ($ result as $ key => $ value){
print_r($ value);
};
Hi there!
I''d like to create a function which input is the result of a mySQL
query.
The output should be exactly the same, only not a mySQL result array,
but a ''real'' array.
So it should also get the fieldnames returned by mySQL and use those as
keys.
I can''t get things to work properly: it should return a
multidimensional array,
like
$result_array[1] = array(
[field1] => field1 value,
[field2] => field2 value,
etc.
)
somehow my result is (with code below)
$result_array[1] = array(
[0] => field1 value,
[field1] => field1 value,
[1] => field2 value,
[field2] => field2 value,
etc.
)
Hope someone can help me on this one.
Frizzle.
+++++ code ++++++
$get_res= mysql_query(QUERY);
if( $res = mysql_fetch_array( $get_res ) )
{
do{
$result[] = $res;
}while( $res = mysql_fetch_array( $get_res ) );
};
foreach( $result as $key => $value ){
print_r($value);
};
这篇关于mySQL结果在函数中实现了数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!