• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

While looping problem in php

I want execute to my file(updation2.php) in cron job

Files:

run.php

This file contains javascript. when i execute this file in my browser, the database content will update correctly.
The output is:
Correct content image
But the javascript file does not support in cron job.

So i am using while looping method(updation2.php). When i am execute this file, the database content will not update correctly.
The output is:
Incorrect content image
I need the solution when execute the updation2.php ,the database content should be updated correctly. like below image
Correct content imagecode.zip
0
jnj_web_solutions
Asked:
jnj_web_solutions
1 Solution
 
lwadwellCommented:
Be careful with variables and scope with PHP.  As you are doing it all within the one main body of the script the variables are defined and used over and over again.
The problem I see with your script is that every time through the loops, you haven't initialised the variables ... e.g.
      while($obj=mysql_fetch_object($res)) {
            $left .= "'".$obj->SId."',";
      }
The $left variable will keep getting longer and longer on every loop through (the while($obj6=mysql_fetch_object($res6)) loop) ... it needs to be re-initialised back to "" at the beginning of the loop.
Similar problems exist for other variables like $Total, $Rv, $Lv ... etc there are possibly more, I stopped looking to be honest.  They need to be set back to zero as every loop through keeps adding to the values from the last loop ... and on.

On an aside note, stylistically the code could be made more simpler and easier ... but that is personal preference.

On an other aside, more could have been done in the database too ... e.g. the big tree walk query could be used to return the totals, e.g.
select sum(LPV) as Lv, sum(RPV) as Rv, sum(LAmount + RAmount) as Total
from (
select leftn as SId, LPV, RPV, LAmount, RAmount
from amount
inner join (select @sid:=(select group_concat(leftn,',',rightn)
                          from amount
                          where find_in_set(sid, @nsid) >= 1)
                 , @nsid:=@sid as fset
            from amount, (select @nsid:='AMSXATUMI',@sid='')v )gr
        on find_in_set(leftn,fset)
where leftn <> ''
union
select rightn as SId, LPV, RPV, LAmount, RAmount
from amount
inner join (select @sid:=(select group_concat(leftn,',',rightn) 
                          from amount
                          where find_in_set(sid, @nsid) >= 1)
                 , @nsid:=@sid as fset
            from amount, (select @nsid:='AMSXATUMI',@sid='')v )gr
        on find_in_set(rightn,fset)
where rightn <> ''
)x

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now