Solved

Query addition

Posted on 2013-01-12
4
154 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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

19 Experts available now in Live!

Get 1:1 Help Now