[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

any reason why variable code isn't couting?

Posted on 2005-05-02
6
Medium Priority
?
201 Views
Last Modified: 2006-11-18
<?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?
0
Comment
Question by:lamerhooDJV
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Promethyl
ID: 13914418
Don't you have to define the variable as global in the class scope?

0
 
LVL 1

Author Comment

by:lamerhooDJV
ID: 13914493
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 :)
0
 
LVL 5

Accepted Solution

by:
ljw87505 earned 2000 total points
ID: 13914592
lamerhooDJV,

I might not understand something here, but you are only incrementing $this->code in the query method which you only call once (right after constructing $db).  Is there some other code that is calling $db->query() with the same $db instance that should be incrementing $this->code()?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:lamerhooDJV
ID: 13914605
oh i see what you are saying, alright... works now :) thanks man
0
 
LVL 7

Expert Comment

by:Promethyl
ID: 13914635
Share with us the working code?
0
 
LVL 1

Author Comment

by:lamerhooDJV
ID: 13914650
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;
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question