Customizing SMF > SMF Coding Discussion

Query for Traffic

<< < (2/19) > >>

colby2152:
Tested it with error...
Database error in block code. Please check the code.

How do I make it into a form?

Jokerâ„¢:
Try this


--- Code: ---<?php

require_once('SSI.php');

num_views();

function num_views($output_method = 'echo')
{
global $smcFunc;

// The specified parent board id
$idboard = 1;
// The first date
$timestamp1 = 1310065085;
// The second date
$timestamp2 = 1312367343;

// Retrieve all child boards who inherit from parent board, then select those who inherit from the previous boards
$request = $smcFunc['db_query']('', 
'SELECT b.id_board FROM {db_prefix}boards AS b
WHERE b.id_parent = {int:parentId}',
array(
'parentId' => $idboard,
)
);

$boards = array();
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$boards[] = $row['id_board'];
}

$smcFunc['db_free_result']($request);

// Next, retrieve all the topics in the boards where the timestamp is between two dates.
// Once found, just output num_views
$request = $smcFunc['db_query']('', 
'SELECT t.num_views FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic)
WHERE t.id_board IN ({array_int:boards_list}) AND m.poster_time BETWEEN {int:date1} AND {int:date2}',
array(
'boards_list' => $boards,
'date1' => $timestamp1,
'date2' => $timestamp2,
)
);

// Your total number of views in this variable
$num_views = 0;
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$num_views += $row['num_views'];

}
$smcFunc['db_free_result']($request);
if ($output_method == 'echo')
{
echo $num_views;
}
}

?>
--- End code ---

colby2152:
What are the variables in the code that I need to replace?

Jokerâ„¢:

--- Quote from: colby2152 on August 03, 2011, 12:10:23 PM ---What are the variables in the code that I need to replace?

--- End quote ---

Just the ones you have asked for ;)



--- Code: ---//board id
$idboard = 1;

// The first date
$timestamp1 = 1310065085;

// The second date
$timestamp2 = 1312367343;
--- End code ---

colby2152:
Hmmm, I didn't edit that code and it threw an error.  What about database IDs?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version