Help refusing duplicates from database.
Posted: Mon Mar 08, 2010 2:32 pm
I have a contacts list I am trying to export to csv so that users can print mailing labels. Some users have the same contact's names and addresses as other users do. My admin print function generates the csv but i do not want duplicate addresses to show up twice or more.
I am trying to use the following code to do so but it isn't working at all. It still prints the full list.
I am trying to use the following code to do so but it isn't working at all. It still prints the full list.
Code: Select all
$query = "SELECT * FROM scml_contacts WHERE NOT address='' AND user_group='".$_SESSION['group']."' ORDER BY lastname ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$needle= $row['first'].','.$row['last'].',';
$pos = strpos($labeldata,$needle);
if($pos == false) {
$labeldata = $row['id'].','.$row['firstname'].','.$row['lastname'].','.$row['nickname'].','.$row['address'].','.$row['zipcode'].','.$row['city'].','.$row['country'].','.$row['web'].','.$row['mail'].','.$row['icq'].','.$row['msn'].','.$row['ym'].','.$row['homephone'].','.$row['workphone'].','.$row['mobilephone'].','.$row['comments'].','.$row['user_group'].','.$row['state'].','.$row['day'].','.$row['month'].','.$row['year']."\n";
fwrite($fh, $labeldata);
}
}