1

如果我使用下面的查询并假设它返回下面的数据集

SELECT p.`id`, 
    s.`name`, 
    d.`deployStatus`,
    d.`deployedDate`
FROM `patches` AS p
LEFT JOIN `deployed` AS d ON d.`PatchID` = p.`id`
LEFT JOIN `servers` AS s ON s.`id` = d.`serverID`
WHERE p.`id` = 2

| id | name | deployStatus | deployedDate |
|____|______|______________|______________|
| 2  | test |      1       |  06/14/2013  |
| 2  | prod |     null     |  06/14/2013  |

有没有一种方法while($row = $results->fetch_assoc()){可以让我只返回“测试”行,而无需更改 sql 查询?

4

1 回答 1

1

使用 if 条件并检查它是否是您想要的行。

while($row = $results->fetch_assoc()){
     if($row['name'] == "test") {
         // echo here your result
     }
}
于 2013-06-26T16:15:46.490 回答