I am trying to build a forum website with php5.2 mysql5.x I am trying to print views for perticular topic but i am stuck with a really weard problem I have written a class called forum as follows(Just kept the essential part) :
[code=php]class Forum
{
private $login;
private $entryTime;
public function __construct($login,$entryTime)
{
$this->login=$login;
$this->entryTime=$entryTime;
}
public function getLogin()
{
return $this->login;
}
public function getEntryTime()
{
return date(“Y-m-d H:i:s”,$this->entryTime);
}
public function getViews()
{
$con=new Connection();
$forumSet=$con->runQuery(“select views from forum where login='”.$this->getLogin().”‘ AND entry_time='”.$this->getEntryTime().”‘”);
$views=array(mysql_fetch_array($forumSet));
$views=$views[0][‘views’];
return $views;
}
}
Now in file i am incrementing the views in database as follows
[code=php]1.require_once(‘Connection.class.php’);
2.$forumId_login=$_POST[‘forumId_login’];
3.$forumId_entryTime=$_POST[‘forumId_entryTime’];
4.$con=new Connection();
5.echo “select * from forum where login='”.$forumId_login.”‘ AND entry_time='”.date(“Y-m-d H:i:s”,$forumId_entryTime).”‘”;
7.$forumSet=$con->runQuery(“select * from forum where login='”.$forumId_login.”‘ AND entry_time='”.date(“Y-m-d H:i:s”,$forumId_entryTime).”‘”);
8.$forum=mysql_fetch_array($forumSet);
9.echo “in//”.$forum[‘views’];// Printing current database value
10.$newForum=new Forum($forumId_login, $forumId_entryTime);
11.echo “out//”.$newForum->getViews();
12.$_views=$newForum->getViews();
///////////
13.$_views=strval(intval($_views)+1);//updating database
14.$con->runQuery(“update forum SET views='”.$_views.”‘ where login='”.$forumId_login.”‘ and entry_time='”.date(“Y-m-d H:i:s”,$forumId_entryTime).”‘”);
Before incrementing the views i am printing the value for current database at line 9 but Magically??? i am getting value which is as if already incremented and as a result when i actually increment it it gets incremented twice ie if my database has value as 1 i get 3,
I don’t know what to do with it?? It seems that increment function gets magically called before i call it, when i remove increment function views never gets incremented, I am new to php is it a php bug?? And when i run the page in google chrome increment happens only once ?? How it is possible that server giving browser dependent code , i am currently working on localserver i localserver causing problem????