In my MySQL table, there are several rows which share the same "case number". I want to display the case numbers on a page but do not want cases which have multiple rows to be displayed more than once. This is basica开发者_JAVA百科lly the code I am using:
//select all records
$query="SELECT * FROM cases ";
$rt=mysql_query($query);
echo mysql_error();                   
while($nt=mysql_fetch_array($rt)){
echo $nt['case'];
echo $nt['date_created'];
}
Any ideas?
using distinct like
SELECT distinct(case) ,date_created FROM cases
you need
SELECT DISTINCT(case_number) FROM cases
you might want to use ORDER BY to order the case_number or by any other field you want.
their is two ways you can do it.
either use distinct or group by like
SELECT
  DISTINCT(case), 
  date_created
FROM
  cases;
or
SELECT
  *
FROM
  cases
GROUP BY
  case;
Use an array in which the current case numbers are present. Loop through the list every time to prevent duplicates.
                                        
                                        
                                        
                                        
                                        
                                        
                                        
                                        
 加载中,请稍侯......
      
精彩评论