[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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

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

0
rowtc2
Asked:
rowtc2
1 Solution
 
Roger BaklundCommented:
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

0
 
rowtc2Author Commented:
Woow, is working perfectly. Thanks and have a nice day !
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now