Page 1 of 1

help with my date login function. SQL command problem

Posted: Sat Dec 10, 2011 5:35 am
by andreea115
hi everyone

i have written a function that give the login date each time registred members log onto the site.

The function works; i.e it records the exact time/date that a member logs onto the site . Thus if a member logs into the site 20 times it will log 20 dates of logins for that member. the function works perfectly.


The problem however occurs when i then try to display the last login date of a member on the 'membership galllery page,.
My incorrectly drafted sql command is causing the script to draft a gallery page for each time the user logged onto the site. however , i only need the last logindate of the user.

it might help if i show you my script

Code: Select all

<?php
       $select = " SELECT  u.first_name,
                                    lo.logindate "; 

      	$from   = " FROM 
                               users u   LEFT  OUTER JOIN  logindate lo
	                          ON u.user_id = lo.user_id

         $where      = " WHERE 
	                u.membership_type = 'Active'  "; 
		   
       $order=  "ORDER BY u.user_id  ASC LIMIT $start, $display ";  
	
	$query = $select.$from.$where. $order ;
	


?>
The above script works .However, it produces a seperate entry for each time the user logged into the site. i however only need it to produce the last entry for the user. i tried to impliment a MAX fucntion but it did not work

below is how i tried to resolve the problem. i amened the SELECT statement to include a max function. it did not work however.

Code: Select all

<?php

$select = " SELECT  u.first_name,
                             MAX(lo.logindate)logindate "; 

?>
please how do i amend my statment to only retrive the last login date from every user.

warm regards

Andreea 115

Re: help with my date login function. SQL command problem

Posted: Sat Dec 10, 2011 6:00 am
by mikeashfield

Code: Select all

$order=  "ORDER BY u.user_id  ASC LIMIT 1";

Re: help with my date login function. SQL command problem

Posted: Sat Dec 10, 2011 8:45 am
by andreea115
hello

i respond to the kind assistance of Mikeashfield
Re:

Code: Select all

                $order=  "ORDER BY u.user_id  ASC LIMIT 1";                                                   
unfortunatley ,i forgot to mention that i am seeking to extract the records for each user. and that these will be put into several pages, thus requiring page pagination.
Acccoridinly, the numbers at the end relate to page pagnation. i.e

Code: Select all

 
 $order=  "ORDER BY u.user_id  ASC LIMIT  $start, $display ";  
	                 
  
so, i really need an sql command that will enable me to extract the last login date for multiple registered users

warm regard


Andreea