我想在数组中显示唯一的客户值,下面是代码;
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0)
{
while ($rad = mysql_fetch_array($sql_result)){ echo $rad['customer'];}
}
如果有人能指导我,如何展示独特的价值观,我将不胜感激?
答案 0 :(得分:0)
尝试这样的事情:
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
$customers = array();
if (mysql_num_rows($sql_result)>0) {
while ($rad = mysql_fetch_array($sql_result)) {
echo $rad['customer'];
$customers[] = $rad['customer'];
}
}
$uniqueCustomers = array_unique($customers);
或者,如果您有唯一ID
if (mysql_num_rows($sql_result)>0) {
while ($rad = mysql_fetch_array($sql_result)) {
echo $rad['customer'];
$customers[$rad['customerId']] = $rad['customer'];
}
}