Mysql和PHP检查是否存在名称和最后联系日期

I have several names and dates in my database, and I am looking for a way to only view an individual's name once and only show that name if their last date of contact was more than 6 months ago.

I know how to view an entry only once using:

$xyz= $db->query("SELECT * FROM dbname GROUP BY name"); 

and i also know how to view a date of less than 6 months using:

if (strtotime($xyz['date']) <= strtotime("-6 months")) {
    do stuff;
}

but I just can not figure out a way to combine them.

In addition to SKY's orig. answer, you want the MAX (most recent) date to be < (older than) 6 mo.

You likely won't need to GROUP BY with this method as only one row should have the max date.

SELECT * 
FROM dbname a
WHERE dateCol < DATE_SUB(now(), INTERVAL 6 MONTH) 
  AND dateCol = (SELECT MAX(dateCol)
                 FROM dbname b
                 WHERE b.name = a.name)
SELECT * 
FROM dbname 
where dateCol > DATE_SUB(now(), INTERVAL 6 MONTH) 
GROUP BY name

take a look at this fiddle: http://sqlfiddle.com/#!9/a581b/6

SELECT
  *
FROM
  dbname
WHERE 
  {YOUR_DATETIME_FIELD}  <= NOW() - INTERVAL 6 MONTH
GROUP BY 
  name

This will show to you user names if their last date of contact was more than 6 months ago but NOT less than 6 months ago

SELECT name 
FROM dbname 
WHERE dateCol < DATE_SUB(now(), INTERVAL 6 MONTH) 
AND name NOT IN (SELECT name FROM dbname WHERE dateCol > DATE_SUB(now(), INTERVAL 6 MONTH))
GROUP BY name