Skip to main content
Inspiring
November 28, 2012
Answered

loopVars

  • November 28, 2012
  • 2 replies
  • 1984 views

I'm not sure if the logic here is best. But how can I make SECTION B loop over and over untill th if condition fails? is it possible to have 'ReceiveLoad2' inside a loop?

var numF:Number = 1;

var numC:Number = 0;

var ReceiveLoad2:LoadVars = new LoadVars();

goNext_btn.onRelease = function () {

          numC = (numF-numF);

          for (i=0; i<30; i++) {

                    if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and numC < 1){

                                        numC++;

                    SenderLoad.codeID = _root.radioStage_mc["radioBtn"+i].idNum.text;

                    SenderLoad.item = _root.radioStage_mc["radioBtn"+i].newCode.text;

                    _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                    SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST");

                    }

          }

}

////SECTION B

ReceiveLoad2.onLoad = function () {

          if (ReceiveLoad2.dat== "successful"){

                    for (i=0; i<30; i++) {

                    if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and _root.radioStage_mc["radioBtn"+i].updateS.text == "" and numC < (numC + numF) and numC < 30){

                              numC++;

                              SenderLoad.codeID = _root.radioStage_mc["radioBtn"+i].idNum.text;

                    SenderLoad.item = _root.radioStage_mc["radioBtn"+i].newCode.text;

 

                    _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                    SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST"); //Here the ReceiveLoad2 repeats ONCE only. How can I make it loop over and over untill th if condition fails? is it possible to have 'ReceiveLoad2' inside a loop?

                    }

          }

 

}

This topic has been closed for replies.
Correct answer kglad

  foreach ($_POST as $key => $value) {

   $$key = $value;

}

$query = "UPDATE db1 SET ";

for($i=0;$i<30;$i++){

if(isset(${"codeID_".$i})){

$query .= "item='" .${'item_'.$i}."' WHERE Code ='".${'codeID_'.$i}.'",";  //<- note: there are single and double quotes

}

}

$query = substr($query, 0, -2);

$result= mysql_query($query);

2 replies

kglad
Community Expert
Community Expert
November 28, 2012

so,  use:

var ReceiveLoad2:LoadVars = new LoadVars();

var SendLoad:LoadVars = new LoadVars();

ReceiveLoad2.onLoad = function () {

// have your php return the number of updated items and do something with that although that number is known when the data are sent (updateItemNum)

}

goNext_btn.onRelease = function () {

          var updateItemNum:Number = 0;

          for (i=0; i<30; i++) {

                    if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text ){

                         SenderLoad["codeID_"+updateItemNum] = _root.radioStage_mc["radioBtn"+i].idNum.text;

                         SenderLoad["item_"+updateItemNum] = _root.radioStage_mc["radioBtn"+i].newCode.text;

                         _root.radioStage_mc["radioBtn"+i].updateS.text = "yes";

                         updateItemNum++;

                    }

          }

     if(updateItemNum>0){

          // the number of updated items is updateItemNum;

          SenderLoad.sendAndLoad("http://www.web.com/D.php",ReceiveLoad2,"POST");

     }

}

Inspiring
November 28, 2012

  foreach ($_POST as $key => $value) {

   $$key = $value;

}

$query = "UPDATE db1 SET item=$key WHERE Code =$value";

$result= mysql_query($query);

I'm not familier with foreach(). Can you help me out here?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 28, 2012

  foreach ($_POST as $key => $value) {

   $$key = $value;

}

$query = "UPDATE db1 SET ";

for($i=0;$i<30;$i++){

if(isset(${"codeID_".$i})){

$query .= "item='" .${'item_'.$i}."' WHERE Code ='".${'codeID_'.$i}.'",";  //<- note: there are single and double quotes

}

}

$query = substr($query, 0, -2);

$result= mysql_query($query);

kglad
Community Expert
Community Expert
November 28, 2012

this:

   if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text and numC < 1){

and should be:

   if (_root.radioStage_mc["radioBtn"+i].textA.text != _root.radioStage_mc["radioBtn"+i].textB.text && numC < 1){

though that code sniippet doesn't make sense.  you will only loop from i=0 to i=0.

so, what are you trying to do with that first code snippet?

section B also makes no sense.  what is that if-statement supposed to check?

Inspiring
November 28, 2012

Thank you Kglad.

In the first snippet, I want to get a start and then when the ReceiveLoad2 is been received I wanted to loop it 30 times.

Also I've used the if statement in the first snippet to check only the first updated record and pass the rest to be handeled by SECTION B.

SECTION B

Only the updated records will be required to be sent via ReceiveLoad2. So I've used the If statement to check only the onces which were updated (textA.text != textB.text /// condition ture - data was updated) && to stop the loop after numC reashes 30

kglad
Community Expert
Community Expert
November 28, 2012

i understand why you might want to only updated changed data but what's the point of waiting until something is received from D.php when nothing is used from that return?