I would like to use a profile count for the php-Nuke profile page instead of the php-BB forum profile so I've made a few changes (seen below). However, while I am receiving no errors, The $total_profile_views is equal to zero and is not incrementing. I added the proper tables and fields to my database so I'm fairly certain that the problem lies in the code below. Could you please let me know where I could have made the error?
Quote: ›
// Profile Views MOD, By Manipe (Begin)
$current_time = time();
$delete_time = $current_time - 86400;
//
// Delete old entries
//
$sql = "DELETE FROM ".$prefix."_profile_views WHERE time < '$delete_time'";
if ( !($result = $db->sql_query($sql)) )
{
echo "Could not retreive profile views<br>";
echo mysql_error();
}
//
// Find out if the same person has visited the same user profile
//
$sql = "SELECT ip_address FROM ".$prefix."_profile_views WHERE ip_address = '$user_ip' AND user_id = '" . $userinfo['user_id'] . "'";
if ( !($result = $db->sql_query($sql)) )
{
echo "Could not retreive profile views<br>";
echo mysql_error();
}
$is_ip_there = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
//
// If so, don't increment the profile views counter
//
if ( empty($is_ip_there['ip_address'][0]))
{
$sql = "INSERT INTO ".$prefix."_profile_views (user_id, time, ip_address) VALUES ('" . $userinfo['user_id'] . "', '$current_time', '$user_ip')";
if ( !($result = $db->sql_query($sql)) )
{
echo "Could not retreive profile views<br>";
echo mysql_error();
}
$sql = "UPDATE ".$prefix."_users SET user_profile_views = user_profile_views + 1 WHERE user_id = '" . $userinfo['user_id'] . "'";
if ( !($result = $db->sql_query($sql)) )
{
echo "Could not retreive profile views<br>";
echo mysql_error();
}
}
//
// Retrieve the number of views
//
$sql = "SELECT user_profile_views FROM ".$prefix."_users WHERE user_id = '" . $userinfo['user_id'] . "'";
if ( !($result = $db->sql_query($sql)) )
{
echo "Could not retreive profile views<br>";
echo mysql_error();
}
$row = $db->sql_fetchrow($result);
$total_profile_views = ( $row['user_profile_views'] ) ? $row['user_profile_views'] : 0;
$db->sql_freeresult($result);
// Profile Views MOD, By Manipe (End)