如何構建一個唯一數組來檢查每個地址字段。PHP構建數據庫行中唯一地址的數組
E.g此刻我得到的一切:
$stmnt = "SELECT `location_id`, `location_address1`, `location_address2`,
`location_town`, `location_region`, `location_postcode`
FROM locations WHERE user_id = '{$id}'";
$results = $db->fetchAll($stmnt);
if(!empty($results)) {
foreach($results as $row) {
if($unique){
$value = $row['location_id'];
$label = implode(", ", array(
'address1' => $row['location_address1'],
'address2' => $row['location_address2'],
'town' => $row['location_town'],
'region' => $row['location_region'],
'postcode' => $row['location_postcode']
));
}
我在想,在那裏if($unique){
是你會檢查這個地址1,地址等通過搜索一些這方面是如何存在的臨時數組中?
爲什麼不只是做一個'SELECT DISTINCT ...'? –
你是否想要獨特的行,或每行內的唯一值? –
這可能會起作用,但會返回不同的{location_id,location_address1,... location_postcode}對。 我不是100%確定,如果這是OP想要的,或者他們想要所有不同的location_id,所有不同的location_address1等。 –