Gossamer Forum
Quote Reply
total hits
I have foud this for cgi

He display the total count for hits

sub {
my ($total) = $DB->table('Links')->select(['SUM(Hits)'])->fetchrow_array;
return $total;
}

I will have the same code, but for php page, how can i do

Thanks in advance
Quote Reply
Re: [michelb] total hits In reply to
probably something like...

$sth = $DB->query("SELECT SUM(Hits) FROM ${PREFIX}Links");
$total = $sth->fetchrow_array();

that should do the trick? I don't think it'll work if you're trying to stick it in the globals though, as I don't beleve that the php side of it pulls on those? Or maybe it might stuff the perl side of it up? I could be wrong...

:)

R.

Last edited by:

ryel01: Dec 14, 2001, 1:12 AM
Quote Reply
Re: [ryel01] total hits In reply to
Thanks for your post

I have tried your code, but i doesn't work

This the code in the page php

<?
require("config.php");

$connect = mysql_connect($base_name,$base_util,$base_pas);
$sql="SELECT mysql_db_query(Hits) FROM Links";
$result = mysql_db_query($base_name1,$sql,$connect);
$res = mysql_num_rows($result);
print "".$res."";
mysql_close($connect);

?>

Whit this code
i have:

Warning: Supplied argument is not a valid MySQL result resource

Thnaks
Quote Reply
Re: [ryel01] total hits In reply to
I'm assuming you're using the PHP front end, and want to add an entry to the globals to do that. Note that you will have to add any entries to globals.php manually. To add that you would do something like:
Code:
'total' => 'create_function(
"", \'global $DB, $PREFIX; $sth = $DB->query("SELECT SUM(Hits) FROM ${PREFIX}Links"); list($total) = $sth->fetchrow_array(); return $total;\'
);'
And use (note the ()'s after the variable):
Code:
<?print $total()?>
in your templates (of course in the default_php templates, and not the 'regular' ones).

It's not too pretty but it works.


Adrian