0

我试图停止在数组中显示重复并显示一次。我已经尝试使用 array_unique() 但文本不会显示,或者我只是使用错误。

include '../../../cpages/cmain/func/init.php';
$result = mysql_query("SELECT * FROM `message` WHERE `to` ='".$user_data['username']."' ");
while ($row =  mysql_fetch_array($result)) {
    $m_id = $row['id'];
    $m_to = $row['to'];
    $m_from = $row['from'];
    $m_text = $row['text'];
    $d_open = $row['open'];
    $d_date = $row['date'];
    $getpro = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `username` ='$m_from' "));
    $pro = $getpro;
    $first_name =$pro['first_name'];
    $last_name =$pro['last_name'];
    $pro_pic = $pro['profile_pic'];
    //profile picture
    $profile_pic = $pro_pic;
  if ($profile_pic == "") {
  $profile_pic = "../cpages/img/default_pic.jpg";
  }
  else
  {
  $profile_pic = "../userdata/".$m_from."/profilepic".$profile_pic;
  }
  //end

  // echo messages
echo '<div><a style="border-style:none;" href="vmge.php?msge='.$m_id.'"><img   src="'.$profile_pic.'" style="border-style:none;" height="50" width="50"  />('.$m_from.')'.ucwords($first_name).'&nbsp'.ucwords($last_name).'<br/>'.$m_text.'</div></a>';
}
4

1 回答 1

0

在查询中使用DISTINCT关键字:

result = mysql_query("SELECT DISTINCT * FROM `message` WHERE `to` ='".$user_data['username']."' ");
于 2012-10-04T07:24:19.293 回答