Author Topic: [Mod] More Statistics for your visitors  (Read 200067 times)

0 Members and 1 Guest are viewing this topic.

Offline rustynet

  • Addicted member
  • ******
  • Posts: 1.031
  • {if msg}{msg}{endif msg}
    • View Profile
    • rustynet.de
[Mod] More Statistics for your visitors
« Reply #30 on: March 15, 2003, 08:49:07 AM »
Thanks V@no  :D



boti

Offline jengwen

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.jenrichardsphotography.com
[Mod] More Statistics for your visitors
« Reply #31 on: March 15, 2003, 04:51:36 PM »
To see total images rated, add this to stats.php
Code: [Select]
//-----------------------------------------------------
//--- Ratings------------------------------------------
//-----------------------------------------------------
   $sql = "SELECT COUNT(image_rating) AS sum
          FROM ".IMAGES_TABLE.
          " WHERE image_rating > 0";
  $row = $site_db->query_firstrow($sql);

  $sum = (isset($row['sum'])) ? $row['sum'] : 0;
  $total_rating = "".$lang['total_rating']."<B> ".$row['sum']."</B>\n";
 
  $site_template->register_vars("total_rating", $total_rating);
unset($total_rating);


You will also have to add to main.php
Code: [Select]
$lang['total_rating'] = "Total Images Rated:";

You can now use {total_rating} in your templates.  Here is an example of mine:
Code: [Select]

<table width="450" border="0" cellspacing="0" cellpadding="1">
                    <tr>
                      <td class="head1">
                        <table width="100%" border="0" cellspacing="0" cellpadding="3">
                          <tr>
                            <td valign="top" class="head1">Gallery Statistics</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row2"> {total_users}<br>
                              {total_votes} <br>
                              {total_comments}<br>
                              {total_hits}<br>
                              {total_downloads}<br>
                              {total_rating} </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    </table>


I tried to make this a template of its own, like whos_online, but couldn't get it to work.  I created it as a separate template called stats.html and added it to the templates used in index.php.  Nothing showed up, so I just hard-coded the html into my home and top templates.  This works, but isn't as nice, so if anyone has it working a cleaner way, could you please let me know what to do.

Offline rustynet

  • Addicted member
  • ******
  • Posts: 1.031
  • {if msg}{msg}{endif msg}
    • View Profile
    • rustynet.de
[Mod] More Statistics for your visitors
« Reply #32 on: March 15, 2003, 06:45:49 PM »
hey thats coll, thanks jengwen  :D


boti

Offline Maweryk

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
[Mod] More Statistics for your visitors
« Reply #33 on: April 05, 2003, 03:35:02 PM »
@v@no: Can U explain me how to extend the gallery stats to

- New Images
- Sent postcards
- ...

like on your website.

Thanks a lot and cheers,

Markus

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] More Statistics for your visitors
« Reply #34 on: April 05, 2003, 07:01:45 PM »
Quote from: Maweryk
@v@no: Can U explain me how to extend the gallery stats

I did it in a "dirty" way, messing up the USERS_TABLE...but then, Jan suggested me this:
Quote
Create a new table like this:
Code:
CREATE TABLE 4images_cat_stats (
  user_id mediumint(8) unsigned NOT NULL default '0',
  cat_id mediumint(8) unsigned NOT NULL default '0',
  cat_hits int(10) unsigned NOT NULL default '0',
  image_hits int(10) unsigned NOT NULL default '0',
  downloads int(10) unsigned NOT NULL default '0',
  postcards int(10) unsigned NOT NULL default '0',
  KEY user_id (user_id),
  KEY cat_id (cat_id)
) TYPE=MyISAM;

The fields user_id and cat_id are reference fields, the other fields contains the hit counts.

You can now store entries for each user_id depending on categories. User with ID 1 visits category with ID 1 the first time: The entry will be created and will be referenced on the user_id and cat_id. If the user visits category with ID 1 again, the entry will be updated depending on his user_id and the cat_id. If he visits category with ID 2, a new entry will be created with user_id = 1 and cat_id = 2. And so on...



You can pull infos about what you want. Relating on user_id's or cat_id's.

Examples:

Fetch 10 users most visited category with ID <cat_id>:
Code:
$sql = "SELECT u.user_id, u.user_name, cs.cat_hits, c.cat_name [...]
        FROM ".USERS_TABLE." u, ".CATEGORIES_TABLE." c, 4images_cat_stats cs
        WHERE cs.cat_id = <cat_id> AND u.user_id = c.user_id AND c.cat_id = cs.cat_id
        ORDER BY cs.cat_hits DESC
        LIMIT 10";

$site_db->query($sql);  


Fetch 10 categories who are most visited by user with ID <user_id>:
Code:
$sql = "SELECT u.user_id, u.user_name, cs.cat_hits, c.cat_name [...]
        FROM ".USERS_TABLE." u, ".CATEGORIES_TABLE." c, 4images_cat_stats cs
        WHERE cs.user_id = <user_id> AND c.cat_id = cs.cat_id AND u.user_id = cs.user_id
        ORDER BY cs.cat_hits DESC
        LIMIT 10";

$site_db->query($sql);  

Jan


I will try do this way somethimes soon, if I successed, I might post it as MOD here ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Maweryk

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
[Mod] More Statistics for your visitors
« Reply #35 on: April 24, 2003, 04:07:49 PM »
Quote from: V@no
Quote from: Maweryk
@v@no: Can U explain me how to extend the gallery stats

I did it in a "dirty" way, messing up the USERS_TABLE...but then, Jan suggested me this:
Quote
Create a new table like this:
Code:
CREATE TABLE 4images_cat_stats (
  user_id mediumint(8) unsigned NOT NULL default '0',
  cat_id mediumint(8) unsigned NOT NULL default '0',
  cat_hits int(10) unsigned NOT NULL default '0',
  image_hits int(10) unsigned NOT NULL default '0',
  downloads int(10) unsigned NOT NULL default '0',
  postcards int(10) unsigned NOT NULL default '0',
  KEY user_id (user_id),
  KEY cat_id (cat_id)
) TYPE=MyISAM;

The fields user_id and cat_id are reference fields, the other fields contains the hit counts.

You can now store entries for each user_id depending on categories. User with ID 1 visits category with ID 1 the first time: The entry will be created and will be referenced on the user_id and cat_id. If the user visits category with ID 1 again, the entry will be updated depending on his user_id and the cat_id. If he visits category with ID 2, a new entry will be created with user_id = 1 and cat_id = 2. And so on...



You can pull infos about what you want. Relating on user_id's or cat_id's.

Examples:

Fetch 10 users most visited category with ID <cat_id>:
Code:
$sql = "SELECT u.user_id, u.user_name, cs.cat_hits, c.cat_name [...]
        FROM ".USERS_TABLE." u, ".CATEGORIES_TABLE." c, 4images_cat_stats cs
        WHERE cs.cat_id = <cat_id> AND u.user_id = c.user_id AND c.cat_id = cs.cat_id
        ORDER BY cs.cat_hits DESC
        LIMIT 10";

$site_db->query($sql);  


Fetch 10 categories who are most visited by user with ID <user_id>:
Code:
$sql = "SELECT u.user_id, u.user_name, cs.cat_hits, c.cat_name [...]
        FROM ".USERS_TABLE." u, ".CATEGORIES_TABLE." c, 4images_cat_stats cs
        WHERE cs.user_id = <user_id> AND c.cat_id = cs.cat_id AND u.user_id = cs.user_id
        ORDER BY cs.cat_hits DESC
        LIMIT 10";

$site_db->query($sql);  

Jan


I will try do this way somethimes soon, if I successed, I might post it as MOD here ;)


Short question! Do U have finished the mod???

Thanks!!!

Cheers,

Markus

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] More Statistics for your visitors
« Reply #36 on: April 24, 2003, 04:17:37 PM »
Quote from: Maweryk

Short question! Do U have finished the mod???

Sorry, no. After all I did to my database and 4images code itself I dont know what is what anymore. Maybe after major cleaning up or starting everything over, I will try finish with this one.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Bomba

  • Full Member
  • ***
  • Posts: 202
    • View Profile
[Mod] More Statistics for your visitors
« Reply #37 on: May 02, 2003, 11:41:26 PM »
how can i have stats like this?

http://www.newman.d2g.com/index.php?template=sitestats
they look great!

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] More Statistics for your visitors
« Reply #38 on: May 03, 2003, 12:04:44 AM »
Yes and no.  Those stats are a combination of this mod and from a logging tool called pphlogger from www.phpee.com

Offline tmacisnbr1

  • Newbie
  • *
  • Posts: 32
    • View Profile
help please
« Reply #39 on: May 17, 2003, 12:17:05 AM »
hello

ive done everything correct i think, but im not sure where to add the tags or how to add them in the html files. When i add the tags, i guess i add them to the wrong place, because when i go to the site, it just gives some weird number, like "total downloads: 5738" or something. Can anyone please help?

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] More Statistics for your visitors
« Reply #40 on: June 01, 2003, 01:21:59 AM »
Hello All,
This looks like a great mod, but I wanna include it on every page on my nav bar (click on link below, you will see the "Site Statistics" section where I want them).

Problem is the templating I'm using uses a file called 4gmenu.php, which is included on all pages and I am able to add things to that file and have them show up on every page (the "Navigation" and "Sponsors" sections are stored in this file).

Is there any way I can have the stats in this file too?
When I try to include stats.php in 4gmenu.php, I get this error:
Quote
Fatal error: Call to a member function on a non-object in /home/gob/public_html/new/gallery/includes/stats.php on line 9

Line 9 contains:
Code: [Select]
$row = $site_db->query_firstrow($sql);

Anybody have any ideas what the problem is?
Thanks!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] More Statistics for your visitors
« Reply #41 on: June 01, 2003, 01:49:20 AM »
try add this before your stats.php include:
Code: [Select]
define('ROOT_PATH', './');
@include(ROOT_PATH.'config.php');
include(ROOT_PATH.'includes/constants.php');
include(ROOT_PATH.'includes/db_'.strtolower($db_servertype).'.php');
$site_db = new Db($db_host, $db_user, $db_password, $db_name);
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] More Statistics for your visitors
« Reply #42 on: June 01, 2003, 01:52:37 AM »
New Error:
Quote
Fatal error: Cannot redeclare class db in /home/gob/public_html/new/gallery/includes/db_mysql.php on line 28

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] More Statistics for your visitors
« Reply #43 on: June 01, 2003, 01:59:04 AM »
I ment inside 4gmenu.php ....?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] More Statistics for your visitors
« Reply #44 on: June 01, 2003, 02:11:36 AM »
Yep, that's inside 4gmenu.php