PHP Web Host - Quality Web Hosting For All PHP Applications Free RavenNuke(tm) Add Ons
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
NoFantasy
Worker
Worker


Joined: Apr 26, 2005
Posts: 114

PostPosted: Mon Nov 06, 2006 6:15 am Reply with quote Back to top

My purpose is to get the top five most visited modules based on NukeSentinels tracked ips table. I keep track for 48 hours.

Here is what i've got so far (which is kinda working, but...):
Code:
SELECT `page`, COUNT( * ) AS `mhits` FROM `nuke_nsnst_tracked_ips` WHERE
(`page` LIKE '%name=Gallery') OR
(`page` LIKE '%name=Forums') OR
(`page` LIKE '%name=Discography') OR
(`page` LIKE '%name=Calendar') OR
(`page` LIKE '%name=Biography') OR
(`page` LIKE '%name=Web_Links') OR
(`page` LIKE '%name=Shout_Box') OR
(`page` LIKE '%name=Downloads') OR
(`page` LIKE '%name=Fans_Worldwide') OR
(`page` LIKE '%name=News') OR
(`page` LIKE '%name=Stories_Archive') OR
(`page` LIKE '%name=Jukebox')
GROUP BY 1 ORDER BY `mhits` DESC LIMIT 5

This will output a table similar to
Code:
|----------------page-------------|----mhits----|
|-/modules.php?name=Gallery-------|-----100-----|
|-/modules.php?name=Forums--------|------90-----|
|-/modules.php?name=Dischography--|------70-----|
|-/modules.php?name=Biography-----|------65-----|
|-/modules.php?name=Web_Links-----|------50-----|

Now, this seems ok, however it won't count any other pages, like /modules.php?name=Forums&file=index
If i use an additional wildcard like:
Code:
SELECT `page`, COUNT( * ) AS `mhits` FROM `nuke_nsnst_tracked_ips` WHERE
(`page` LIKE '%name=Gallery%') OR
(`page` LIKE '%name=Forums%') OR
(`page` LIKE '%name=Discography%') OR
.....
GROUP BY 1 ORDER BY `mhits` DESC LIMIT 5

That won't work either, now it counts the most visited page, not module.
Code:
|----------------page--------------------------|----mhits----|
|-/modules.php?name=Forums&file=index----------|-----350-----|
|-/modules.php?name=Forums&file=viewforum&f=4--|-----220-----|
|-/modules.php?name=Gallery--------------------|-----100-----|
...

So, what do i need to do to count all rows containing "Forums", "Gallery", etc and group them properly?
View user's profile Send private message
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Mon Nov 06, 2006 3:40 pm Reply with quote Back to top

Hmm I see the SQL problem, I'm not sure how to fix it. You need to some way to grab a substring and count on that.

I know MS_Analysis kept track of module usage, but I believe they actually generate a count that is stored in seperate tables.
View user's profile Send private message Visit poster's website
NoFantasy
Worker
Worker


Joined: Apr 26, 2005
Posts: 114

PostPosted: Mon Nov 06, 2006 6:16 pm Reply with quote Back to top

True, MS_Analysis does keep track. However, it's from-date-to-date module visits only...or totals.
I could of course grab data from there and make the task simple....and somehow inaccurate..., but getting the data from the NS-tables would be more than great since those data is based on latest 48 hours (or how long you chose to track) visits, not the date.
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Mon Nov 06, 2006 6:19 pm Reply with quote Back to top

NoFantasy, how often do you need to generate the stats? If it is not "real-time", then you could write code to do this in two steps. First do what you are doing, but use PHP code to do the eregi or similar other string function to populate a temporary table with your data, but the PHP code would strip out the module name. Then, you could do another SUM/GROUP BY to get the final tally.

That is a bit "brute-force", but it would work if you didn't need it to be real-time.
View user's profile Send private message Visit poster's website
NoFantasy
Worker
Worker


Joined: Apr 26, 2005
Posts: 114

PostPosted: Mon Nov 06, 2006 6:35 pm Reply with quote Back to top

It's being generated on every page actually..in a block i made me for showing some basic info on the traffic. I could of course do like
Code:
SELECT COUNT( * ) AS `Forums`
FROM `nuke_nsnst_tracked_ips`
WHERE (`page` LIKE '%name=Forums%')

SELECT COUNT( * ) AS `Gallery`
FROM `nuke_nsnst_tracked_ips`
WHERE (`page` LIKE '%name=Gallery%')

for every module i wanted to get data of, but it would generate about 15 queries, for every page view, which i feel is a bit...well, too much.
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Mon Nov 06, 2006 6:41 pm Reply with quote Back to top

Ok, so you ARE thinking real-time then... bummer. I looked up using RegEx on the MySQL documentation, but could not find what could work. The problem is that you really cannot substr it as the length of the module name is not consistent. You might be better off writing something in modules.php (or mainfile.php) which stores the data you need on your own table.
View user's profile Send private message Visit poster's website
NoFantasy
Worker
Worker


Joined: Apr 26, 2005
Posts: 114

PostPosted: Tue Nov 07, 2006 7:05 am Reply with quote Back to top

I played around with subqueries as i understood Evaders suggested and accidently pasted wrong code into the query window...guess what, it worked, lol
Code:
SELECT
COUNT(`page`) AS `Total`,
COUNT(`page` LIKE '%name=Gallery%' OR NULL) as `Gallery`,
COUNT(`page` LIKE '%name=Forums%' OR NULL) as `Forums`,
COUNT(`page` LIKE '%name=Discography%' OR NULL) as `Discography`,
COUNT(`page` LIKE '%name=Calendar%' OR NULL) as `Calendar`,
COUNT(`page` LIKE '%name=Biography%' OR NULL) as `Biography`,
COUNT(`page` LIKE '%name=Web_Links%' OR NULL) as `Web_Links`,
COUNT(`page` LIKE '%name=Shout_Box%' OR NULL) as `Shout_Box`,
COUNT(`page` LIKE '%name=Downloads%' OR NULL) as `Downloads`,
COUNT(`page` LIKE '%name=Fans_Worldwide%' OR NULL) as `Fans_Worldwide`,
COUNT(`page` LIKE '%name=News%' OR NULL) as `News`,
COUNT(`page` LIKE '%name=Stories_Archive%' OR NULL) as `Stories_Archive`,
COUNT(`page` LIKE '%name=Jukebox%' OR NULL) as `Jukebox`
FROM `nuke_nsnst_tracked_ips`

Don't ask me why the OR NULL has to be in there, but if it's not, the query will count totals.
This query will show as
Code:
|--Total---|--Gallery--|--Forums--.....
|---xxxx--|---xxxx---|---xxxx----.....


Well, at least it works in some way, i get the numbers i want. Now i have to figure out the php code to show the 5 highest numbers only, heh...any hints?
View user's profile Send private message
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Tue Nov 07, 2006 8:40 am Reply with quote Back to top

Hmm I take it they are coming out as columns rather than rows, so you couldn't use LIMIT

You could write some PHP code to put them into an array and sort it. Then pull the top 5 entries off the array.
View user's profile Send private message Visit poster's website
NoFantasy
Worker
Worker


Joined: Apr 26, 2005
Posts: 114

PostPosted: Tue Nov 07, 2006 9:43 am Reply with quote Back to top

...true, they are. Having them coming out as
Code:
|--Gallery------|-----xxx-----|
|--Forums------|-----xxx-----|
|--Discography-|-----xxx-----|

instead of
Code:
|--Total---|--Gallery--|--Forums--|
|---xxxx--|---xxxx---|---xxxx----|

would make everything alot easier, so im still looking out for a better query. Can't give up when walked this far Very Happy
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum