我在我的数据库查询中遇到了什么问题PHP
问题描述:
我有一个数据库和一张表,它看起来像这样我在我的数据库查询中遇到了什么问题PHP
ID图片描述。
在我的PHP代码中,我尝试获取“图片”,它现在只是一个文本,而且是描述。但是,我总是得到
未定义指数:说明
未定义指数:图片
这里我的代码:
<?php include ("db.php");
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Picture, Description FROM family WHERE ID = 1 ";
$result = $conn->query($sql)
or die ("MySQL-Error: " . $conn->error);
if ($result->num_rows >0) {
while ($row = mysqli_fetch_row($result)){
echo "Pic: " . $row["Picture"]. " - Description: " . $row["Description"]. "
}
}
else {
echo "Not good";
}
$conn->close();
echo "Connected successfully"; ?>
是什么错误意味着
编辑:我解决它将mysqli_fetch_row
更改为mysqli_fetch_assoc
答
这里的问题:
while ($row = mysqli_fetch_row($result))
你应该使用mysqli_fetch_array()
或mysqli_fetch_assoc()
'的print_r($行)'或按照手册。 –