mysql多维数据

时间:2013-10-24 06:02:50

标签: php mysql

我需要从我的数据库输出多行选择,如下所示。它输出第二行但不是第一行,并返回警告“警告:非法字符串偏移'char_name'”

$i = 0;
while($array = @mysql_fetch_assoc($query)){
    $row[$i] = $array;
    $char = $row[$i]['char_id'];
    $$char['char_name'] = $row[$i]['char_name'];  /warning is on this line

    echo $char . " " . $$char['char_name'];$i++;
}

2 个答案:

答案 0 :(得分:1)

你能否重建代码:

$i = 0;
while($array = @mysql_fetch_assoc($query)){
    $row[$i] = $array;
    $char = $row[$i]['char_id'];
    $char_name = $row[$i]['char_name']; 

    echo $char . " " . $char_name;
    $i++;
}

答案 1 :(得分:0)

将此更改为

$$char['char_name'] = $row[$i]['char_name'];  /warning is on this line
echo $char . " " . $$char['char_name'];
$i++;

这个

$char['char_name'] = $row[$i]['char_name'];  /warning is on this line
echo $char . " " . $char['char_name'];
$i++;