2

I Have a for loop that i have been trying to work with to achieve a given goal, The loop should increment only the Y parameter for every time it runs, when i do a dry code for the same thing it works but if i try a loop everything becomes misaligned

Here is the hard coded sample

         //   for($s=0; $s<count($standards);$s++){

            $pdf->SetXY(32, 132);
            $pdf->Write(1, $standards[0]->name);

            $pdf->SetXY(106, 132);
            $pdf->Write(1, $standards[0]->rs_code);

            $pdf->SetXY(153, 132);
            $pdf->Write(1, round($standards[0]->potency,2));

             $pdf->SetXY(32, 139);
            $pdf->Write(1, $standards[1]->name);

            $pdf->SetXY(106, 139);
            $pdf->Write(1, $standards[1]->rs_code);

            $pdf->SetXY(153, 139);
            $pdf->Write(1, round($standards[1]->potency,2));

           // }

Now the dynamic for loop, I want that if the first Y values for the three XYs is 132, on the next run it should be 132+7, and continue incrementing like that for all loop runs, the below is returning data but misaligned as compared to the static one above

         $ya=(int)132;

           for($s=0; $s<count($standards);$s++){

            $pdf->SetXY(32, $ya+=7);
            $pdf->Write(1, $standards[$s]->name);

            $pdf->SetXY(106, $ya+=7);
            $pdf->Write(1, $standards[$s]->rs_code);

            $pdf->SetXY(153, $ya+=7);
            $pdf->Write(1, round($standards[$s]->potency,2));

             $pdf->SetXY(32, $ya+=7);
            $pdf->Write(1, $standards[$s]->name);

            $pdf->SetXY(106, $ya+=7);
            $pdf->Write(1, $standards[$s]->rs_code);

            $pdf->SetXY(153, $ya+=7);
            $pdf->Write(1, round($standards[$s]->potency,2));

            }

the result should be something like

 A      B     C
 D      E     F

and not

  A 
           B    
                  C

  D     
           E   
                   F
1
  • 1
    You only need the fourth $ya+=7, the rest should be just $ya as you only want to increment it once. Or perhaps the first and fourth when you start at 125 instead. Commented Feb 28, 2015 at 10:30

1 Answer 1

1

Hope this helps. You need to increment it just once. That too after printing first three statements.

       $ya=(int)132;

       for($s=0; $s<count($standards);$s++){

        $pdf->SetXY(32, $ya);
        $pdf->Write(1, $standards[$s]->name);

        $pdf->SetXY(106, $ya);
        $pdf->Write(1, $standards[$s]->rs_code);

        $pdf->SetXY(153, $ya);
        $pdf->Write(1, round($standards[$s]->potency,2));

         $pdf->SetXY(32, $ya+=7);
        $pdf->Write(1, $standards[$s]->name);

        $pdf->SetXY(106, $ya);
        $pdf->Write(1, $standards[$s]->rs_code);

        $pdf->SetXY(153, $ya);
        $pdf->Write(1, round($standards[$s]->potency,2));

        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.