我怎样才能回应这个价值?

时间:2013-03-10 05:42:17

标签: php

我需要做的就是echo array pocket $ row [0]。

while ($row = mysqli_result::fetch_array($result)) {
    echo '<br>' . $row[1];
}
echo $row[0];

我用Google搜索,但结果没有帮助。我知道我错过了一些愚蠢的东西,但我很感激你的帮助!

我正在尝试回显数据库列'ID'。我想要回应的数据的一个例子是'3'。

2 个答案:

答案 0 :(得分:0)

要调试整行,请写下:

var_dump($row)

要输出列ID,请写下:

while ($row = mysqli_result::fetch_array($result)) {
    var_dump($row); // This will output all values for each row as they're looped through
    echo '<br>' . $row['ID'];
}
var_dump($row); // dumps the last row of the returned results, or false if no rows.
echo $row['ID']; // echos the ID of the last row. However if there are no rows, this will not work.

请注意,正如@Daedalus指出的那样,$row是一个数组,所以var_dump行实际上只是用于调试。因为数组有多个值,所以PHP不知道如何显示它。您需要编制$row的每个元素的显示方式。

答案 1 :(得分:0)

随时复制$ row [0]。

$lastZero = "";
while ($row = mysqli_result::fetch_array($result)) {
    echo '<br>' . $row[1];
    $lastZero = $row[0];
}
echo $lastZero;
相关问题