vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Total views on non-vb page (Query included) (https://vborg.vbsupport.ru/showthread.php?t=41512)

wooolF[RM] 07-25-2002 02:21 PM

Total views on non-vb page (Query included)
 
]hello...

I'll make it fast and easy : All I want is to display TOTAL VIEWS on a non-vb page.

QUERY: "SELECT SUM(views) AS threadviews FROM thread"
Where file will be : OUTSIDE of vbb folder
How will I include this PHP file : <? include("totalviews.php"); ?>

That is it... quick and simple... I may sound like an idiot, but right now I'm exploding because of madness... I have tried to get this script to work in the past 5 hours... I spent over 3 hours on the forum searching for include, non-vb page etc... I skimmed over 300 threads and I looked into all hacks...

<-- desperate... :ermm:


PS: I have tried to use Tobedogg's hack as a base ( https://vborg.vbsupport.ru/showthrea...t=online+nonvb ) but had no positive results

wooolF[RM] 07-25-2002 02:28 PM

]Here's code I tried to use...
PHP Code:

<?

$path = "/home/wooolf/WWW/forum/admin"; // set the path to your admin directory. see above for info about this.


require("$path/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);

$cookievalue = mysql_query("SELECT value FROM setting WHERE varname = 'cookietimeout'") or die("oops1");
$cookietimeout = mysql_result($cookievalue, 0, 0);
$datecut = time()-$cookietimeout;

$total = mysql_query("SELECT SUM(views) AS threadviews FROM thread") or die("goddamnit");
while($total = mysql_fetch_array($total)):
    $totalviews = number_format($total[threadviews]);
endwhile;

echo("$totalviews");

?>

Results: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/wooolf/WWW/forum/totalviews.php on line 15
469,001


Line 15:
PHP Code:

while($total mysql_fetch_array($total)): 


PS::: this is just one of the 300 ways I have tried to do it... :(

wooolF[RM] 07-25-2002 02:38 PM

]Here's FULL script which WORKS in the vBB folder, but does NOT work when u try to include it from outside :

PHP Code:

unusable... 


wooolF[RM] 07-25-2002 02:42 PM

1 Attachment(s)
]Here's NICE nice output that I'm getting out of this script

And this output does NOT want to be included any places... :( I mean it does not work if you will try to include it as php file in a portal or phpnuke or whatever ( a webinterface outside of vBB folder )

Logician 07-25-2002 03:11 PM

Try this one:

PHP Code:

<?php
mysql_connect
("$servername""$dbusername""$dbpassword") or die("Couldnt find MYSQL!");
mysql_select_db("$dbname")  or die ("Couldnt find DB!");
$cekilen=mysql_query("SELECT SUM(views) AS threadviews FROM thread");
if (
mysql_error()) {echo "mySQL error:"; echo mysql_error(); exit;}
else
{echo 
mysql_result($cekilen,0);} 
?>

Your query returns 1 row/1 field, so your dont need to deal with "while"s or "mysql_fetch_array"s. "mysql_result" does the trick..;)

wooolF[RM] 07-25-2002 03:35 PM

]yay! :] it worked! thanx Logician!!! :D

used this script:
PHP Code:

<?

$path = "/home/wooolf/WWW/forum/admin"; // set the path to your admin directory. see above for info about this.


require("$path/config.php");
mysql_connect("$servername", "$dbusername", "$dbpassword") or die("Couldnt find MYSQL!");
mysql_select_db("$dbname")  or die ("Couldnt find DB!");
$totalviews=mysql_query("SELECT SUM(views) AS threadviews FROM thread");
if (mysql_error()) {echo "mySQL error:"; echo mysql_error(); exit;}
else
{echo mysql_result($totalviews,0);} 
?>


wooolF[RM] 07-25-2002 04:19 PM

]everything from my script works except 3 thing:
PHP Code:

{echo mysql_result($totalonline,0);} echo("<br><br>");
{echo 
mysql_result($numbervisible,0);} echo("<br><br>");
{echo 
mysql_result($numberguest,0);} echo("<br><br>"); 

This means I get parse errors when I wan to see how many members are online in total/members/guests...

I use this script for it:
PHP Code:

<?

$path = "/home/wooolf/WWW/forum/admin";                                                                            //where's config
require("$path/config.php");                                                                                    //get config settings


mysql_connect("$servername", "$dbusername", "$dbpassword") or die("Couldnt find MYSQL!");                        //connect to the server
mysql_select_db("$dbname")  or die ("Couldnt find DB!");                                                        //select proper DB

// STARTING QUERIES HERE
$aktiveuser = mysql_query("SELECT COUNT(userid) as anzahl FROM user");
$registers = mysql_query("SELECT userid, username FROM user ORDER BY userid DESC LIMIT 1");
$datecut=time()-$cookietimeout;
$loggedins=mysql_query("SELECT COUNT(*) AS sessions FROM session WHERE userid=0 AND lastactivity>$datecut");
$numberguest=$loggedins['sessions'];
$loggedins=mysql_query("SELECT DISTINCT session.userid,username,invisible,usergroupid
                              FROM session
                              LEFT JOIN user ON (user.userid=session.userid)
                              WHERE session.userid>0 AND session.lastactivity>$datecut
                              ORDER BY invisible ASC, username ASC");
while ($loggedin=mysql_query($loggedins)) {
    $numberregistered++;
    if ($loggedin['invisible']==0 or $bbuserinfo['usergroupid']==6) {
      $numbervisible++;
    }
}
$totalonline=$numberregistered+$numberguest;
$numberinvisible=$numberregistered-$numbervisible;
// END OF QUERIES HERE

if (mysql_error()) {echo "mySQL error:"; echo mysql_error(); exit;}                                                //show error if any
else
{echo mysql_result($totalonline,0);} echo("<br><br>");
{echo mysql_result($numbervisible,0);} echo("<br><br>");
{echo mysql_result($numberguest,0);} echo("<br><br>");

?>

Any ideas? :) thanx for any help

wooolF[RM] 07-25-2002 04:30 PM

]looks like something wrong with
PHP Code:

$loggedins=mysql_query("SELECT COUNT(*) AS sessions FROM session WHERE userid=0 AND lastactivity>$datecut"); 

... ? :/

Logician 07-25-2002 04:44 PM

Quote:

Originally posted by wooolF[RM]
everything from my script works except 3 thing:
PHP Code:

{echo mysql_result($totalonline,0);} echo("<br><br>");
{echo 
mysql_result($numbervisible,0);} echo("<br><br>");
{echo 
mysql_result($numberguest,0);} echo("<br><br>"); 

This means I get parse errors when I wan to see how many members are online in total/members/guests...

$totalonline=$numberregistered+$numberguest;
$numberinvisible=$numberregistered-$numbervisible;

$totalonline and $numberinvisible variables are not query result resources, they are ordinary integer variables so why do you use them inside mysql_result?

As for "$loggedins": use that one in mysql_result because it is a query result. So you should use it like that:

$numberguest=mysql_result($loggedins,0);

wooolF[RM] 07-25-2002 04:55 PM

]Hmmm... now I use this script:
PHP Code:

<?

$path = "/home/wooolf/WWW/forum/admin";                                                                            //where's config
require("$path/config.php");                                                                                    //get config settings


mysql_connect("$servername", "$dbusername", "$dbpassword") or die("Couldnt find MYSQL!");                        //connect to the server
mysql_select_db("$dbname")  or die ("Couldnt find DB!");                                                        //select proper DB

// STARTING QUERIES HERE
$aktiveuser = mysql_query("SELECT COUNT(userid) as anzahl FROM user");
$registers = mysql_query("SELECT userid, username FROM user ORDER BY userid DESC LIMIT 1");
$datecut=time()-$cookietimeout;
$loggedins=mysql_query("SELECT COUNT(*) AS sessions FROM session WHERE userid=0 AND lastactivity>$datecut");
$numberguest=mysql_result($loggedins,0);
$loggedins=mysql_query("SELECT DISTINCT session.userid,username,invisible,usergroupid
                              FROM session
                              LEFT JOIN user ON (user.userid=session.userid)
                              WHERE session.userid>0 AND session.lastactivity>$datecut
                              ORDER BY invisible ASC, username ASC");
while ($loggedin=mysql_query($loggedins)) {
    $numberregistered++;
    if ($loggedin['invisible']==0 or $bbuserinfo['usergroupid']==6) {
      $numbervisible++;
    }
}
$totalonline=$numberregistered+$numberguest;
$numberinvisible=$numberregistered-$numbervisible;
// END OF QUERIES HERE

if (mysql_error()) {echo "mySQL error:"; echo mysql_error(); exit;}                                                //show error if any
else
{echo $totalonline;} echo("<br><br>");
{echo $numbervisible;} echo("<br><br>");
{echo mysql_result($numberguest,0);} echo("<br><br>");

?>


same result : Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/wooolf/WWW/forum/totalviews.php on line 43

:( :( :( :( :(

line 43:
PHP Code:

{echo mysql_result($numberguest,0);} echo("<br><br>"); 



All times are GMT. The time now is 12:28 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02022 seconds
  • Memory Usage 1,784KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (11)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete