View counter not accurate

hello all how u doing ok so am using this view counter

// sort out counter
if (empty($auction_data['counter']))
{
	$query = "INSERT INTO `" . $DBPrefix . "auccounter` (`auction_id`, `counter`) VALUES (:counter, 1)";
	$params = array();
	$params[] = array(':counter', $id, 'int');
	$db->query($query, $params);
	$auction_data['counter'] = 1;
}
else
{
	
	if (!in_array($id, $_SESSION['WEBID_VIEWED_AUCTIONS']))
	{
		$query = "UPDATE " . $DBPrefix . "auccounter set counter = counter + 1 WHERE auction_id = :auction_id";
		$params = array();
		$params[] = array(':auction_id', $id, 'int');
		$db->query($query, $params);
		$_SESSION['WEBID_VIEWED_AUCTIONS'][] = $id;
	}
}

it works but it keep jumping

from 1 it jumps to 3 sometime from 3 it goes to 8 and then start working well any assist on what making it to act this way will be grateful thanks

it suppose to b a session counter

nothing in the posted code seems to be wrong. Where is $_SESSION['WEBID_VIEWED_AUCTIONS'] being generated?

but still act weird

Are you absolutely 100% sure you are the only person testing the code, that no other persons are viewing as well throwing off the numbers you expected?

yes 150% even sure it also does so offline

am still having issues with this need help

Should 'int' be PDO::PARAM_INT ?
http://php.net/manual/en/pdostatement.bindparam.php

data_type
Explicit data type for the parameter using the PDO::PARAM_* constants.

am using int

If you missed what I meant by my question, I’ll rephrase it.

If the function expects a constant (eg. PDO::PARAM_INT) and you are passing a string (i.e. 'int') might that have something to do with the problem?

oh not at all

I haven’t tested, and I haven’t seen any documentation saying strings are OK, so I don’t know. But even if you’re absolutely certain code isn’t ignoring it as an unrecognized argument and accepts it to mean INT, it seems that would be undocumented behavior and it wouldn’t be safe to assume it will never change. Is there a good reason why you can’t change the code to pass the PDO::PARAM_* constant?

cause the codes are base on an int so change might end of affecting something i can forseen which is something i dont want to happen

Are you displaying errors?

<?php
error_reporting(-1);
ini_set('display_errors',1);
?>

not showing any error

$stmt = $db->query($query, $params);
$stmt->debugDumpParams();
print_r($db->errorInfo());

EDIT: That last one all sorts of wrong.

Noting that these commands (and the ones before) should be left on for a complete cycle from 1 to 9.

sorry i dont get what u saying

where does that sit in here or replace

// sort out counter
if (empty($auction_data['counter']))
{
	$query = "INSERT INTO `" . $DBPrefix . "auccounter` (`auction_id`, `counter`) VALUES (:counter, 1)";
	$params = array();
	$params[] = array(':counter', $id, 'int');
	$db->query($query, $params);
	$auction_data['counter'] = 1;
}
else
{
	
	if (!in_array($id, $_SESSION['WEBID_VIEWED_AUCTIONS']))
	{
		$query = "UPDATE " . $DBPrefix . "auccounter set counter = counter + 1 WHERE auction_id = :auction_id";
		$params = array();
		$params[] = array(':auction_id', $id, 'int');
		$db->query($query, $params);
		$_SESSION['WEBID_VIEWED_AUCTIONS'][] = $id;
	}
}

still battling with this not working well yet

this is workiing ok but not well it keep doubling its counter if i refresh page some times it does act weird sometimes it does please what am i doing wrong here thanks

// sort out counter
if (empty($auction_data['counter']))
{
	$query = "INSERT INTO `" . $DBPrefix . "auccounter` (`auction_id`, `counter`) VALUES (:counter, 1)";
	$params = array();
	$params[] = array(':counter', $id, 'int');
	$db->query($query, $params);
	$auction_data['counter'] = 1;
}
else
{
	
	if (!in_array($id, $_SESSION['WEBID_VIEWED_AUCTIONS']))
	{
		$query = "UPDATE " . $DBPrefix . "auccounter set counter = counter + 1 WHERE auction_id = :auction_id";
		$params = array();
		$params[] = array(':auction_id', $id, 'int');
		$db->query($query, $params);
		$_SESSION['WEBID_VIEWED_AUCTIONS'][] = $id;
	}
}

this is working ok but not well it keep doubling its counter if i refresh page some times it does act weird sometimes it does please what am i doing wrong here thanks

// sort out counter
if (empty($auction_data['counter']))
{
	$query = "INSERT INTO `" . $DBPrefix . "auccounter` (`auction_id`, `counter`) VALUES (:counter, 1)";
	$params = array();
	$params[] = array(':counter', $id, 'int');
	$db->query($query, $params);
	$auction_data['counter'] = 1;
}
else
{
	
	if (!in_array($id, $_SESSION['WEBID_VIEWED_AUCTIONS']))
	{
		$query = "UPDATE " . $DBPrefix . "auccounter set counter = counter + 1 WHERE auction_id = :auction_id";
		$params = array();
		$params[] = array(':auction_id', $id, 'int');
		$db->query($query, $params);
		$_SESSION['WEBID_VIEWED_AUCTIONS'][] = $id;
	}
}