Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

While looping problem in php

Posted on 2012-09-08
1
Medium Priority
?
633 Views
Last Modified: 2012-09-09
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
Comment
Question by:jnj_web_solutions
1 Comment
 
LVL 25

Accepted Solution

by:
lwadwell earned 2000 total points
ID: 38379419
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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 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