Solved

Query addition

Posted on 2013-01-12
4
155 Views
Last Modified: 2013-01-17
Hi,

I use the following query to count unique pageviews, grouped by date.

$sqlStr = '
SELECT
	date(viewdate) AS myDate,
	COUNT(DISTINCT userip) AS myCount
FROM
	archive_views
GROUP BY
	myDate
ORDER BY
	myDate DESC;
';

Open in new window


I need to add this part to it, but not sure how.

SUM(earnings) AS mySum WHERE approved='true' DISTINCT userip

Open in new window


The idea is to count all approved earnings from a specific date, but only from unique visitors (my affiliates only get paid per 24 hour unique visitor).
0
Comment
Question by:kgp43
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 38770585
Can you just use

SELECT
      date(viewdate) AS myDate,
      COUNT(DISTINCT userip) AS myCount
FROM
      archive_views
GROUP BY
      myDate, userip
ORDER BY
      myDate DESC;
';
0
 

Author Comment

by:kgp43
ID: 38770593
Update: let me test a bit and get back to you.

 - I do not need the approved='true'
0
 

Author Comment

by:kgp43
ID: 38770614
Does not work.

And "SUM(earnings) AS mySum," does not count earnings per unique 24 hour IP either... I think. Hmm, hard one.

<?php
$sqlStr = '
SELECT
	date(viewdate) AS myDate,
	SUM(earnings) AS mySum,
	COUNT(DISTINCT userip) AS myCount
FROM
	archive_views
GROUP BY
	myDate, userip
ORDER BY
	myDate DESC;
';

# Query
$view_query = mysql_query($sqlStr) or die(mysql_error());
while($view_fetch = mysql_fetch_array($view_query)) {	
	?>

	<tr>
		<td>Date: <?php echo date("F jS, Y", strtotime($view_fetch['myDate'])); ?></td>
		<td>Views: <?php echo $view_fetch['myCount'] ?></td>
		<td>Amount: <?php echo "$".round($view_fetch['mySum'], 2); ?></td>
	</tr>
	
<?php
}
?>

Open in new window

0
 

Author Comment

by:kgp43
ID: 38770644
I changed my script a bit, so I can just use this instead.

$sqlStr = '
SELECT
	date(viewdate) AS myDate,
	SUM(earnings) AS mySum,
	COUNT(DISTINCT userip) AS myCount
FROM
	archive_views
GROUP BY
	myDate
ORDER BY
	myDate DESC;
';

Open in new window


Going to close the question soon, unless something else comes up regarding this query.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

930 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

10 Experts available now in Live!

Get 1:1 Help Now