Jump to content

Two separate nuke Total Hits counter questions.


djw2

Recommended Posts

Hey,

 

I\'m very green to the whole PHP/MySQl world so go easy on me. :D

 

First of all I\'m installing PHP-Nuke 6.5 and I\'m using MySQLadmin to access the MySQL. Now then, I have two issues occurring in the same counter.

 

First.

 

I\'ve installed a Total Hits counter block. The counter tracks hourly hits, daily hits, as well as averages per hour, day, month and year. When I installed the counter the nuke_stats_date and nuke_stats_month were set to zero variables and had no tables established.

 

What I did was build a table for A day in nuke_stats_date and A table for the month in nuke_stats_month. All seemed good, my \"warning: division by zero error went away and the counter was counting. We I got up this morning the counter was no longer counting NEW hits for the day. I had to go back in and make a table for today.

 

My question is.... Do I have to build the tables for every day of the year, or can the daily rollover be automated somehow?

 

If my nuke_stats_date isn\'t updating automatically them I bet come October my nuke_stats_month won\'t either.

 

Obviously I’m not much of a MySQL wiz so I could use someone pointing me in the right direction.

 

Second

 

The Nuke Total Hits counter I have will show today\'s hits, yesterday\'s hits and then average hits per hour, day, month and year. As well as total hits for the site. The problem is as part of the nuke it counts everything... it counts me over and over, it counts every single page click regardless where it is, it counts reloads, it just counts everything.

 

I really like the counters features, but I only want to count unique page views on the index in like 12-hour blocks.

 

How could the script be modified to make that happen?

 

Here\'s my site.

 

http://www.right2left.org

 

and here\'s the counter script.

 

 

 

[php:1:8889ef7164]
<?php

/********************************************************/
/* Block for PHP-Nuke 6.0 thru 6.5 */
/* By: fun-room (Webmaster@fun-room.com) */
/* http://www.fun-room.com/ */
/* Copyright © 2003 by Fun-room Network */
/********************************************************/

if (eregi(\"block-Hits.php\", $PHP_SELF)) {Header(\"Location: index.php\");
die();}

global $nukeurl, $prefix, $startdate, $dbi;
$nbhits = \"<center>\";
$content = \"\";

///////////////////////////////////////////////////////////////////////////////////////////////////////

$type = \"text\"; // defines type of counter (text or gfx)

////////////////////////////////////////////////////////////////////////////////////////////////////////

/* Hits Total */
$result = sql_query(\"SELECT count FROM $prefix\"._counter.\" WHERE type=\'total\' AND var=\'hits\'\", $dbi);
$count_holder = sprintf (\"%07d\", implode(mysql_fetch_row($result), $dbi));
mysql_free_result ($result);
if ($type == \"text\")
$nbhits .= $count_holder;
else
for ($n = 0; $n < strlen($count_holder); $n++) ($nbhits .= \"<img src=\"images/led/{$count_holder[$n]}.gif\" bordercolor=\"#FFFFFF\" border=\"1\">\");

/* Hits for Today */
$t_time = time();
$t_year = date(\"Y\", $t_time);
$t_month = date(\"n\", $t_time);
$t_date = date(\"j\", $t_time);
$result = sql_query(\"SELECT hits FROM $prefix\"._stats_date.\" WHERE year=\'$t_year\' AND month=\'$t_month\' AND date=\'$t_date\'\", $dbi);
list($today) = sql_fetch_row($result, $dbi);

/* Hits for Yesterday */
$y_time = $t_time - 86400;
$y_year = date(\"Y\", $y_time);
$y_month = date(\"n\", $y_time);
$y_date = date(\"j\", $y_time);
$result = sql_query(\"SELECT hits FROM $prefix\"._stats_date.\" WHERE year=\'$y_year\' AND month=\'$y_month\' AND date=\'$y_date\'\", $dbi);
list($yesterday) = sql_fetch_row($result, $dbi);

/* Hourly Hits */
$result = sql_query(\"SELECT count(*) FROM $prefix\"._stats_hour.\"\", $dbi);
list($hours) = sql_fetch_row($result, $dbi);
$hourly = number_format($count_holder/$hours, 0);

/* Daily Hits */
$result = sql_query(\"SELECT count(*) FROM $prefix\"._stats_date.\"\", $dbi);
list($days) = sql_fetch_row($result, $dbi);
$daily = number_format($count_holder/$days, 0);

/* Monthly Hits */
$result = sql_query(\"SELECT count(*) FROM $prefix\"._stats_month.\"\", $dbi);
list($months) = sql_fetch_row($result, $dbi);
$monthly = number_format($count_holder/$months, 0);

/* Yearly Hits */
$result = sql_query(\"SELECT count(*) FROM $prefix\"._stats_year.\"\", $dbi);
list($years) = sql_fetch_row($result, $dbi);
$yearly = number_format($count_holder/$years, 0);

/* Server Time */
$Time = date(\"d M Y\");
$Today = date(\"H:i:s\");
$Offset = date(\"O\");
$nbhits .= \" </center>\";

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* TOTAL HITS */
$content .= \"<div align=\"center\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"95%\">n\";
$content .= \"<tr><td><center><small>\"._WERECEIVED.\"</small><br><br>$nbhits<br><small>\"._PAGESVIEWS.\" $startdate</small></center></td></tr>n\";
$content .= \"</table><hr>n\";
$content .= \"<b><u>\"._BHITS.\"</u></b><br>\";
$content .= \"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"95%\">n\";
$content .= \"<tr><td width=\"65%\"><big><b>·</b></big> \"._BTD.\"</td>n\";
$content .= \"<td width=\"35%\"><p align=\"right\"><b><a href=\"modules.php?name=Statistics&op=DailyStats&year=$t_year&month=$t_month&date=$t_date\">$today</a></b></td></tr>n\";
$content .= \"<tr><td width=\"65%\"><big><b>·</b></big> \"._BYD.\"</td>n\";
$content .= \"<td width=\"35%\"><p align=\"right\"><b><a href=\"modules.php?name=Statistics&op=DailyStats&year=$y_year&month=$y_month&date=$y_date\">$yesterday</a></b></td></tr>n\";
$content .= \"</table><hr>n\";
$content .= \"<b><u>\"._BHITA.\"</u></b><br>\";
$content .= \"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"95%\">n\";
$content .= \"<tr><td width=\"65%\"><big><b>·</b></big> \"._BHOUR.\"</td>n\";
$content .= \"<td width=\"35%\"><p align=\"right\">$hourly</td></tr>n\";
$content .= \"<tr><td width=\"65%\"><big><b>·</b></big> \"._BDAIL.\"</td>n\";
$content .= \"<td width=\"35%\"><p align=\"right\">$daily</td></tr>n\";
$content .= \"<tr><td width=\"65%\"><big><b>·</b></big> \"._BMONT.\"</td>n\";
$content .= \"<td width=\"35%\"><p align=\"right\">$monthly</td></tr>n\";
$content .= \"<tr><td width=\"65%\"><big><b>·</b></big> \"._BYEAR.\"</td>n\";
$content .= \"<td width=\"35%\"><p align=\"right\">$yearly</td></tr>n\";
$content .= \"</table><hr>\";
$content .= \"<b><u>Server \"._BTIME.\"</u></b><br>\";
$content .= \"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"95%\">n\";
$content .= \"<tr><td width=\"40%\"><big><b>·</b></big> \"._BTIME.\"</td>n\";
$content .= \"<td width=\"60%\"><p align=\"right\">$Today</td></tr>n\";
$content .= \"<tr><td width=\"40%\"><big><b>·</b></big> \"._BDATE.\"</td>n\";
$content .= \"<td width=\"60%\"><p align=\"right\">$Time</td></tr>n\";
$content .= \"<tr><td width=\"40%\"><big><b>·</b></big> \"._BZONE.\"</td>n\";
$content .= \"<td width=\"60%\"><p align=\"right\">$Offset</td></tr>n\";
$content .= \"</table></div>\";
?>
?>[/php:1:8889ef7164]


?>[/code]

Link to comment
Share on other sites

Hey,

 

Like I said, I don\'t know a lot about PHP coding or working in MySQL but it seems to be making the calculations okay. If I go in and add a new table in the nuke_stats_date it comes back with averages.

 

What I need to figure out is when 9-18-2003 becomes 9-19-2003 it makes it\'s own table. Isn\'t there a way to just put it on a loop?

 

 

Thanks,

 

Dan

Link to comment
Share on other sites

It creates a new table every day? That\'s horrible!

 

In order to change this, you\'d need to make some really big modifications to both the code AND the database. If I may, I\'d suggest another counter. They aren\'t really worth a table a day, and it\'s pointless to make any modifications at all, since there are much more efficient counters out there.

 

s0urce

Link to comment
Share on other sites

Okay,

 

I guess my green is really gonna show now. :oops:

 

The counter isn\'t creating anything, that\'s the problem.

 

I don\'t guess I want it to do a table a day... :roll:

 

If...

 

nuke_stats_date

nuke_stats_hour

nuke_stats_month

nuke_stats_year

 

are tables, then...

 

9 18 2003

9 19 2003

9 20 2003

 

are variables... in the nuke_stats_date table?

 

If this is true :?: then tables are already established, they\'re just not working properly and I can\'t figure out if it\'s the database or the counter that is screwed up.

 

That’s why I posted the code. I just thought someone more experienced than I could look at it and say… right here on line such and such the code is supposed to be telling the database to ________ and it’s not doing so… or, that the code looks good hence check and see that your database is set to do __________.

 

When it becomes a new day (midnight) I want the database to just update itself (roll to the next day), rather than me having to manually update it (build a new variable :?: )... every day, every month, every year.

 

I\'m sorry if I misled you, I hope this clears some of this gibberish up.

 

Thanks,

 

Dan

Link to comment
Share on other sites

Hey,

 

I went back to the beginning before I ever goofed with anything and reinstalled the nuke to start over. So I\'m back to the beginning.

 

Just as a reference. I’m using PHP Nuke 6.5, php v. 4.3.2, and MySQL v. 4.0.15-standard. The counter script is your standard hits today, hits yesterday, total hits, average hits per hour, per day, month, per year type counter found in nukes.

 

The error looks like this...

 

Warning: Division by zero in /home/dwhelan/public_html/test/blocks/block-User_Info.php on line 177

 

Now, when I check the date table (nuke_stats_date) in phpMyAdmin it has the fields listed like this...

 


Field     Type     Attributes Null Default Extra           Action

year   smallint(6)             No     0            Ch Dr Pri Ind Uni Full

month  tinyint(4)              No     0            Ch Dr Pri Ind Uni Full

date   tinyint(4)              No     0            Ch Dr Pri Ind Uni Full

hits   bigint(20)              No     0            Ch Dr Pri Ind Uni Full

 

My question is... shouldn\'t those default variables be filled in?

 

Something more along the lines of...

 


Field     Type     Attributes Null Default Extra           Action

year   smallint(6)             No     1            Ch Dr Pri Ind Uni Full

month  tinyint(4)              No     12           Ch Dr Pri Ind Uni Full

date   tinyint(4)              No     365          Ch Dr Pri Ind Uni Full

hits   bigint(20)              No     0            Ch Dr Pri Ind Uni Full

 

 

I sure would appreciate some help on this; I\'m having a hell on a time hacking it out.

 

 

Thanks a lot.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.