...

View Full Version : Using COUNT To Display Results



tomyknoker
08-23-2007, 03:02 AM
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...


$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`";

Nightfire
08-23-2007, 03:09 AM
$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 :o

tomyknoker
09-02-2007, 02:12 AM
Anyone help me with this at all??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum