View counter not accurate


#1

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


#2

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


#4

but still act weird


#5

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?


#6

yes 150% even sure it also does so offline


#7

am still having issues with this need help


#8

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.


#9

am using int


#10

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?


#11

oh not at all


#12

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?


#13

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


#14

Are you displaying errors?

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

#15

not showing any error


#16
$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.


#17

sorry i dont get what u saying


#18

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;
	}
}

#19

still battling with this not working well yet