0

I am trying to show the last "date" of a picture that was added, related to a specific person.

If I enter an additional element under ORDER BY: ,timestamp DESC There is no change to the result. With every group I get the date of the first picture.

Some people have one image, others have twent five or more. There are about 1500 people in the database.

All other data/image is returned correctly.

I cannot find any reference on the internet to my problem, more a generalisation.

Thanks

The output is:-

Person's - Person -  Nos Of - Last Picture 
Picture     Name    Pictures     "Date"
--------   ------   --------  ------------

image       Tony       5      26th June 2012

image       Beth       1      6th January 2011

image       John       2      5th May 2012

The msql_query is:-

<?php

   function person($person_id) {

      $persons = array();

      $persons_query = mysql_query("
         SELECT `persons`.`person_id`, `persons`.`person_name`, 
         LEFT(`persons`.`person_description`, 50) as `person_description`, 
         `person_images`.`timestamp`, `person_images`.`image_person_id`, 
         `person_images`.`person_name`, `person_images`.`ext`, 
          COUNT(`person_images`.`image_person_id`) as `image_count`
          FROM `persons`
          LEFT JOIN `person_images`
          ON `persons`.`person_id` = `person_images`.`person_id`
         LEFT JOIN `person_images`
         ON `persons`.`person_id` = `person_images`.`person_id`
         WHERE `persons`.`member_id` = ".$_SESSION['member_id]
         GROUP BY `persons`.`person_id`
         ORDER BY `persons`.`person_name`, 
     ");

     While ($persons_row = mysql_fetch_assoc($persons_query)) {

        $persons[] = array(
            'person_id'              => $persons_row['person_id'],
           'person_name'            => $persons_row['person_name'],
           'person_description'     => $persons_row['person_description'],
           'timestamp'               => $persons_row['timestamp'],
           'image_person_id'         => $persons_row['image_person_id'],
           'ext'                     => $persons_row['ext'],
           'count'                   => $persons_row['image_count']
        );
     }
     return $persons;
   }
?>
4

1 回答 1

2

我认为您的问题与订购无关,因为您只对最近图片的日期感兴趣。那么你试试这个怎么样:

MAX(timestamp) GROUP BY person_id
于 2013-01-05T06:01:06.163 回答