Jump to content

echoing total hits for a page


droidus

Recommended Posts

am i going about this in the right way?  it doesn't seem to be echoing anything  :P

 

<?php
  mysql_select_db($database_uploader, $uploader); 
  $totalHits = mysql_query("SELECT SUM(hits) AS totalHits FROM userDataTracking")
  or die(mysql_error()); 
	mysql_close($con);
	echo $totalHits;
	?>

Link to comment
https://forums.phpfreaks.com/topic/245475-echoing-total-hits-for-a-page/
Share on other sites

mysql_query returns a resource, you have to fetch the data using the resource:

 

mysql_select_db($database_uploader, $uploader); 
$totalHits = mysql_query("SELECT SUM(hits) AS totalHits FROM userDataTracking") or die(mysql_error()); 

// Add this line to fetch the data
$row = mysql_fetch_row($totalHits);

mysql_close($con);

// Access the data from the array
echo $row[0];

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.