Latest visitors of a profile. How to show just 1 record per id if he visited  a profile more than once?

Posted on 2009-04-23
Last Modified: 2013-12-12
I have a website. I have users with profiles. Every user can see who has visited his profile.
If a user visit(click) my profile  4 times for exampla , i see at latest visitors 4 entries. I want to show just one entry (the latest by date).

I have a separate table for reecording visitors with these 4 columns:
id_v     id_member_was_visited     id_member_who_is_visiting    date

Any help will be appreciated ,because i am a beginner mysql. Thanks.
$sql_count = "select * from table_visitors WHERE id_member_was_visited='$id_member_was_visited'  ORDER BY date DESC LIMIT 10";

$result = mysql_query ($sql_count);

while($row = mysql_fetch_array($result)){

Open in new window

Question by:rowtc2
    LVL 39

    Accepted Solution

    Try this:
    $sql_count = "select id_member_who_is_visiting,max(date) as date from table_visitors 
      WHERE id_member_was_visited='$id_member_was_visited'  
      GROUP BY id_member_who_is_visiting
      ORDER BY date DESC LIMIT 10";

    Open in new window


    Author Closing Comment

    Woow, is working perfectly. Thanks and have a nice day !

    Featured Post

    Easy Project Management (No User Manual Required)

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now