[英]SELECT DISTINCT rows
I am trying to output each of the rows by the value driver_profileId. 我试图通过值driver_profileId输出每一行。
Currently this only outputs one value to the page. 当前,这仅向页面输出一个值。 I am expecting a list of all the unique values in the cell.
我期望单元格中所有唯一值的列表。
Why is this not outputting more than one row? 为什么这不输出多于一行?
$query = "SELECT DISTINCT(driver_profileId) FROM driver_profiles";
$result = mysqli_query($conn, $query)or die(mysqli_error($conn));
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
foreach ($row as $key) {
echo $key;
}
I believe your issue is because you're only fetching one row . 我相信您的问题是因为您只获取一行 。 Try something more like this:
尝试更多类似这样的方法:
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo $row['driver_profileId'];
}
This will keep fetching rows until there are no more in the result set. 这将继续获取行,直到结果集中没有更多行为止。 See the manual page for
mysqli_fetch_array
: 请参见
mysqli_fetch_array
的手册页:
Returns an array that corresponds to the fetched row or NULL if there are no more rows for the resultset represented by the result parameter.
返回与获取的行相对应的数组;如果result参数表示的结果集没有更多行,则返回NULL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.