|
--------------------------------------------------------
MYSQL:
字段 类型
fid smallint(6)
fup smallint(6)
type enum('group', 'forum', 'sub')
name varchar(50)
status tinyint(1)
数据库数据为:
fid fup type name status
1 0 group 默认 1
2 1 forum 默认论坛 1
--------------------------------------------------------
为了生成这样的结果:
$forum0 = Array
(
['fid'] => 1
['fup'] => 0
['type'] => 'group'
['name'] => '默认'
['status'] => 1
)
$forum1 = Array
(
['fid'] => 2
['fup'] => 1
['type'] => 'forum'
['name'] => '默认论坛'
['status'] => 1
)使用了下面的代码,但是结果不对,请问下面的代码如何修改?
--------------------------------------------------------
PHP:
function forumlist_cache($forumlist) {
global $db;
$num = 0;
while($row = $db->fetch_array($forumlist)) {
$template = "\$forum{$num} = Array \n(\n";
foreach($row as $key => $value) {
//!echo gettype($row[$key]); // 发现类型都是string
$template .= "\t['$key'] = " . (!is_int($row[$key]) ? $row[$key] : "'$row[$key]'") . "\n";
}
$template .= ")\n";
$num++;
echo $template;
}
}
-------------------------------------------------------------------------------- |
|