PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 307,108 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,041 people online right now. Registration is fast and FREE... Join Now!




funny updating problem

 

funny updating problem

ghqwerty

5 Nov, 2009 - 11:01 AM
Post #1

if($spareTime > 0){ $this->writeCode(); }
Group Icon

Joined: 8 Aug, 2008
Posts: 748



Thanked: 24 times
Dream Kudos: 25
My Contributions
ok so in the function below i wish to first find out how many villages the user has loop through them, work out crops used and crops consumed pretty straight forward.
CODE

    function evaluateCropUsage($user){
        $query = "select * from population where user = $user";
        $dbdata = mysql_query($query, $this->dblink);        
        while($row = mysql_fetch_array($dbdata)){
            $this->getPop($user, $row['location']);
            $cropsUsed = 0;
            for($x=1;$x<6;$x++){
                $cropsUsed += $this->pop[$this->dbPop[$x]] * $this->cropUsage[$x-1];
                
            }
            $totProduction = 0;
            for($x=0;$x<5;$x++){
                $workers = $this->pop[$this->dbFarmers[$x]];
                $production = $this->farmerProduction[$x]*$workers;
                $totProduction += $production;        
            }            
            $differance = $totProduction - $cropsUsed;
            echo $differance;            
            $this->pop['crops'] += $differance;
                $this->updatePopulation();
            print_r($this->pop);
        }
    }


with the differance as above i use $this->pop['crops'] += $differance

and then update it however it comes out wierd. in the print_r it shows the second array as just Array([crops] => 0) regardless of whatever the differance was and then renames stuff to other rows its as if it copies one row into another.

its wierd and as far as im aware shouldnt be going wrong

any ideas ??


User is offlineProfile CardPM
+Quote Post


RudiVisser

RE: Funny Updating Problem

5 Nov, 2009 - 01:42 PM
Post #2

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,891



Thanked: 139 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
Hmm.. 2 things I can think of really (after looking just at the bottom of the code):
Does $this->updatePopulation(); modify $this->pop at all??
Have you tried a simple $this->pop['crops'] = 20; before the print_r (or before the $this->updatePopulation(); call) to see if that updates it correctly?
User is offlineProfile CardPM
+Quote Post

ghqwerty

RE: Funny Updating Problem

5 Nov, 2009 - 11:30 PM
Post #3

if($spareTime > 0){ $this->writeCode(); }
Group Icon

Joined: 8 Aug, 2008
Posts: 748



Thanked: 24 times
Dream Kudos: 25
My Contributions
i was just about to post another comment with updatePopulation when i noticed that in updatePopulation it uses a where clause to determine which village to modify and i use a session in the location part, however in here the session wont change hence the feeling of 'merging' the rows. so if i just add 2 parameters to updatePopulation for user and location it should work, right ?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 12:41PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month