Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Using COUNT To Display Results

    I have a table in my database which holds a loginDate and user ID each time a user signs into to my site, this is so I can then display the results and see what users are signing in more than others, I have pretty much got the whole thing working, I can pull the data out and display it in an HTML table, the only bit I am having trouble with is, is say a user has logged in 5 times, they get displayed 5 times in the list I want to only display each user once but show in a column in the HTML table the amount of times they logged in, I'm assuming it's a COUNT query but not sure... Below is my query, it's coming form search form where the user can enter a date To and date From... Any help would be greatly appreciated...

    PHP Code:
    $query "SELECT tblmembers.*, tbllogins.*
              FROM tblmembers 
            LEFT JOIN tbllogins ON (tblmembers.ID = tbllogins.MembersID)
            WHERE tblmembers.FirstName LIKE '%$firstName%'  
            AND LastName LIKE '%$lastName%'  
            AND Email LIKE '%$email%'
            AND State LIKE '%$state%' ;
            
    if(!empty($loginDateEarly) && !empty($loginDateLate)) 

    $query .= " 
    AND DATE(loginDateBETWEEN '$loginDateEarly' AND '$loginDateLate'"; 


    $query .= " 
    ORDER BY `LastName`"; 

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $query "SELECT tblmembers.*, tbllogins.*
              FROM tblmembers 
            LEFT JOIN tbllogins ON (tblmembers.ID = tbllogins.MembersID)
            WHERE tblmembers.FirstName LIKE '%$firstName%'  
            AND LastName LIKE '%$lastName%'  
            AND Email LIKE '%$email%'
            AND State LIKE '%$state%' "
    ;
            
    if(!empty(
    $loginDateEarly) && !empty($loginDateLate)) 

    $query .= " AND DATE(loginDate) BETWEEN '$loginDateEarly' AND '$loginDateLate'"


    $query .= " ORDER BY `LastName`"
    Missing your closing " after AND State LIKE '%$state%' ;

    As for your problem, I don't know yet. Too tired to work it out

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Anyone help me with this at all??


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •