我有一张如下表:
hub dep
A B
A C
B D
B E
B F
E G
我使用mysql select来获取查询,我的代码如下所示:
$sql = "SELECT dep FROM handd WHERE hub='B'";
$result = $conn->query( $sql );
$row = $result->fetch_assoc();
while($row = $result->fetch_assoc()) {
echo "id: " . $row["dep"]."<br>";
}
但它只给出了如下结果:
id: E
id: F
我想知道D在哪里?
答案 0 :(得分:1)
$row = $result->fetch_assoc();
此行存储&#39; B D&#39;的结果。它实际应该是:
$sql = "SELECT dep FROM handd WHERE hub='B'";
$result = $conn->query( $sql );
while($row = $result->fetch_assoc()) {
echo "id: " . $row["dep"]."<br>";
}