我在 MySQL 中有一个名为 lynked_v1 的表和一个名为 probability_single_free 的列
+----------------------------------+
| id | probability_single_free |
| ---------------------------------|
| 0 | 100.00 |
| 1 | 100.00 |
| 2 | 100.00 |
| 3 | 100.00 |
| 4 | 100.00 |
| 5 | 100.00 |
| 6 | 100.00 |
| 7 | 100.00 |
+----------------------------------+
我正在尝试使用以下命令回显每一行:
<?php
error_reporting(-1);
ini_set('display_errors', true);
require_once ('/var/www/html/MySQL/mysqli_connect.php');
echo "Connected successfully";
$query = "SELECT probability_single_free FROM lynked_v1";
$response = @mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($response)) {
echo $row[0];
echo $row[1];
echo $row[2];
echo $row[3];
echo $row[4];
echo $row[5];
echo $row[6];
echo $row[7];
}
?>
$row[0] 在屏幕上打印正常。但是对于其余的行,我得到以下错误:
Notice: Undefined offset: 1 in /var/www/html/index.php on line 56
Notice: Undefined offset: 2 in /var/www/html/index.php on line 57
Notice: Undefined offset: 3 in /var/www/html/index.php on line 58
Notice: Undefined offset: 4 in /var/www/html/index.php on line 59
Notice: Undefined offset: 5 in /var/www/html/index.php on line 60
Notice: Undefined offset: 6 in /var/www/html/index.php on line 61
Notice: Undefined offset: 7 in /var/www/html/index.php on line 62
如何分别打印每一行?
最佳答案
使用这段代码:
<?php
error_reporting(-1);
ini_set('display_errors', true);
require_once ('/var/www/html/MySQL/mysqli_connect.php');
echo "Connected successfully";
$query = "SELECT probability_single_free FROM lynked_v1";
$response = @mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($response)) {
echo $row["probability_single_free"];
}
?>
它会像魅力一样工作)
关于php - MySQL PHP undefined offset 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39988390/