求大神指点一二

WBOY
Release: 2016-06-23 14:01:08
Original
964 people have browsed it

数据库连接

$rs = mysql_query("select id,degree,min,max,prize,v from magic_config");while($r = mysql_fetch_assoc($rs)) { $prize_arr[] = $r;}print_r($prize_arr);
Copy after login

看了下 出来的是
Array (
[0] => Array ( [id] => 1 [degree] => 1 [min] => 1 [max] => 5 [prize] => 一等奖 [v] => 1 )
[1] => Array ( [id] => 2 [degree] => 122 [min] => 97 [max] => 125 [prize] => 二等奖 [v] => 1 ))

但想要的是
$prize_arr = array(
array('id'=>1,'degree'=>1,'min'=>1,'max'=>5,'prize'=>'一等奖','v'=>89),
array('id'=>2,'degree'=>32,'min'=>7,'max'=>35,'prize'=>'不要灰心','v'=>1));
该怎么办?


回复讨论(解决方案)

Array 大小写不一样貌似不行吧
[]这个要变成单引号 汉字也要加单引号
Array ( ...)应该是$prize_arr = array( ...);这样
'v'=>89), 后面也要逗号吧 貌似

你用var_dump($prize_arr)

$prize_arr = array( array('id'=>1,'degree'=>1,'min'=>1,'max'=>5,'prize'=>'一等奖','v'=>89), array('id'=>2,'degree'=>32,'min'=>7,'max'=>35,'prize'=>'不要灰心','v'=>1)); 
Copy after login
Copy after login

print_r($prize_arr); 得
Array (
[0] => Array ( [id] => 1 [degree] => 1 [min] => 1 [max] => 5 [prize] => 一等奖 [v] => 89 )
[1] => Array ( [id] => 2 [degree] => 32 [min] => 7 [max] => 35 [prize] => 不要灰心 [v] => 1 )
)
var_export($prize_arr); 得
array (
0 => array ( 'id' => 1, 'degree' => 1, 'min' => 1, 'max' => 5, 'prize' => '一等奖', 'v' => 89, ),
1 => array ( 'id' => 2, 'degree' => 32, 'min' => 7, 'max' => 35, 'prize' => '不要灰心', 'v' => 1, ),
)

只不过是显示格式不同而已,并没有改变 $prize_arr 的值

$prize_arr = array( array('id'=>1,'degree'=>1,'min'=>1,'max'=>5,'prize'=>'一等奖','v'=>89), array('id'=>2,'degree'=>32,'min'=>7,'max'=>35,'prize'=>'不要灰心','v'=>1)); 
Copy after login
Copy after login

print_r($prize_arr); 得
Array (
[0] => Array ( [id] => 1 [degree] => 1 [min] => 1 [max] => 5 [prize] => 一等奖 [v] => 89 )
[1] => Array ( [id] => 2 [degree] => 32 [min] => 7 [max] => 35 [prize] => 不要灰心 [v] => 1 )
)
var_export($prize_arr); 得
array (
0 => array ( 'id' => 1, 'degree' => 1, 'min' => 1, 'max' => 5, 'prize' => '一等奖', 'v' => 89, ),
1 => array ( 'id' => 2, 'degree' => 32, 'min' => 7, 'max' => 35, 'prize' => '不要灰心', 'v' => 1, ),
)

只不过是显示格式不同而已,并没有改变 $prize_arr 的值
版主 现在蛋疼的是
$rs = mysql_query("select id,degree,min,max,prize,v from magic_config"); while($r = mysql_fetch_assoc($rs)) {  $prize_arr[] = $r; } print_r($prize_arr); 
Copy after login

不起作用 无语啦 不知道为神马

这个问题太难了

if (! $rs) {        echo  mysql_error ();        exit;    }
Copy after login
Copy after login

打印错误

var_export($prize_arr); 就是你想要的结果

if (! $rs) {        echo  mysql_error ();        exit;    }
Copy after login
Copy after login

打印错误
这个要放在哪里呢~

$rs = mysql_query("select id,degree,min,max,prize,v from magic_config");if (! $rs) {        echo  mysql_error ();        exit;    }
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