lamerhooDJV
asked on
any reason why variable code isn't couting?
<?php
class db
{
public function query($query)
{
if(isset($this->code))
$this->code = $this->code+1;
else
$this->code = 0;
return mysql_query($query);
}
public function fetch_array($query)
{
return mysql_fetch_array($query);
}
}
$db = NEW db();
$q = $db->query("select * table");
for($i = 0; $row = $db->fetch_array($q); ++$i)
{
echo $row['progname']."<br />";
}
echo "value :";
echo $db->code;
?>
basically, when I access $db->code it says "0" always... any reason why it isn't counting the number of queries? there is about 1400 there... so I know that it is function as I intended it to, just not counting... any ideas?
class db
{
public function query($query)
{
if(isset($this->code))
$this->code = $this->code+1;
else
$this->code = 0;
return mysql_query($query);
}
public function fetch_array($query)
{
return mysql_fetch_array($query);
}
}
$db = NEW db();
$q = $db->query("select * table");
for($i = 0; $row = $db->fetch_array($q); ++$i)
{
echo $row['progname']."<br />";
}
echo "value :";
echo $db->code;
?>
basically, when I access $db->code it says "0" always... any reason why it isn't counting the number of queries? there is about 1400 there... so I know that it is function as I intended it to, just not counting... any ideas?
Don't you have to define the variable as global in the class scope?
ASKER
Not quite sure, but that wouldn't explain that it passes the 0 to it within the scope. And then when I access it, it puts just 0. It's being set and able to be seen, but it won't count. So there is something going on with the life of the variable. Like it's leaving the scope and then being recreated. I think. Not sure though, that's why I'm here :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh i see what you are saying, alright... works now :) thanks man
Share with us the working code?
ASKER
class db
{
public function query($query)
{
if($this->code != 0)
++$this->code;
else
$this->code = 1;
return mysql_query($query);
}
public function fetch_array($query)
{
if($this->code != 0)
++$this->code;
else
$this->code = 1;
return mysql_fetch_array($query);
}
}
$db = NEW db();
$q = $db->query("select * from universal_programs");
for($i = 0; $row = $db->fetch_array($q); ++$i)
{
echo $row['progname']."<br />";
}
echo "value :";
echo $db->code;
{
public function query($query)
{
if($this->code != 0)
++$this->code;
else
$this->code = 1;
return mysql_query($query);
}
public function fetch_array($query)
{
if($this->code != 0)
++$this->code;
else
$this->code = 1;
return mysql_fetch_array($query);
}
}
$db = NEW db();
$q = $db->query("select * from universal_programs");
for($i = 0; $row = $db->fetch_array($q); ++$i)
{
echo $row['progname']."<br />";
}
echo "value :";
echo $db->code;