Replacing code based on static variables to variable variables.

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Replacing code based on static variables to variable variables.

    Can anyone give me some help or tips in converting this code to take 2 variables that will specify the number of Pack
    type lines and the number of Single type lines. We use it to create a web page that allows us to split a garment
    delivery over multiple dates and and to specify the number and size of garments in a pack and the number and size of
    individual garments in the delivery. 3 of each has been enough until now. However we are finding new customers that want
    it spread over as many as 5 to 8 of each type pack and single.

    Everything is stored in an array $RPack.
    Easy to do as i new there were only ever goung to be 6 lines.

    $maxC is the number of colours available (usually 3)
    $maxR is the number of lengths each colour is available (usually 3)
    $maxH is the number of sizes each length is available in. (Between 8 & 14)

    Input() is a function for drawing HTML input boxes of the format

    Input (Size,Value,Class,Name,Maxlength,Readonly)

    I think what I need is to use variable variables but I am having a hard time getting my head around it so any tips and
    advice would be very gratefully received.

    // Create Data Entry, Boxes for Amt,Qty Total and Date
    for ($z=0; $z<$maxC; $z++){
    for ($y=0; $y<$maxR; $y++){
    //Set Temp variables to 0 or ""
    $ThisColour = "";
    $ThisRange = "";
    $ColourSize="";
    $P_In0="";
    $P_In1="";
    $P_In2="";
    $S_In0="";
    $S_In1="";
    $S_In2="";
    $Total_In="";
    $RatioTotal_In="";
    $LineAmt0 = 0;
    $LineAmt1 = 0;
    $LineAmt2 = 0;
    $LineAmtS0 = 0;
    $LineAmtS1 = 0;
    $LineAmtS2 = 0;
    $ColourSize = Input(8,$RatioColours{$z}.' '.$RatioRange{$y};,formstyle,Colour_Size,10);

    for ($i=0; $i<$maxH; $i++){
    // Check already an entry if so use it, if not add default order line to singles1 and set rest to 0
    if($fldfldMDA==1){

    $Pack0 = Input(3,$RPack[0]{$i}{$z}{$y},formstyle,Pack0.$i.$z.$y,10);
    $LineAmt0 = $LineAmt0 + $RPack[0]{$i}{$z}{$y};
    $ColSumP0{$i}{$z}{$y} = ($RPack[0]{$i}{$z}{$y}*$RPack[0]{$Qty}{$z}{$y});

    $Pack1 = Input(3,$RPack[1]{$i}{$z}{$y},formstyle,Pack1.$i.$z.$y,10);
    $LineAmt1 = $LineAmt1 + $RPack[1]{$i}{$z}{$y};
    $ColSumP1{$i}{$z}{$y} = ($RPack[1]{$i}{$z}{$y}*$RPack[1]{$Qty}{$z}{$y});

    $Pack2 = Input(3,$RPack[2]{$i}{$z}{$y},formstyle,Pack2.$i.$z.$y,10);
    $LineAmt2 = $LineAmt2 + $RPack[2]{$i}{$z}{$y};
    $ColSumP2{$i}{$z}{$y} = ($RPack[2]{$i}{$z}{$y}*$RPack[2]{$Qty}{$z}{$y});

    $Singles0 = Input(3,$RPack[3]{$i}{$z}{$y},formstyle,Singles0.$i.$z.$y,10);
    $LineAmtS0 = $LineAmtS0 + $RPack[3]{$i}{$z}{$y};
    $ColSumS0{$i}{$z}{$y} = ($RPack[3]{$i}{$z}{$y}*$RPack[3]{$Qty}{$z}{$y});

    $Singles1 = Input(3,$RPack[4]{$i}{$z}{$y},formstyle,Singles1.$i.$z.$y,10);
    $LineAmtS1 = $LineAmtS1 + $RPack[4]{$i}{$z}{$y};
    $ColSumS1{$i}{$z}{$y} = ($RPack[4]{$i}{$z}{$y}*$RPack[4]{$Qty}{$z}{$y});

    $Singles2 = Input(3,$RPack[5]{$i}{$z}{$y},formstyle,Singles2.$i.$z.$y,10);
    $LineAmtS2 = $LineAmtS2 + $RPack[5]{$i}{$z}{$y};
    $ColSumS2{$i}{$z}{$y} = ($RPack[5]{$i}{$z}{$y}*$RPack[5]{$Qty}{$z}{$y});

    $ColTotal =
    $ColSumP0{$i}{$z}{$y}+$ColSumP1{$i}{$z}{$y}+$ColSu mP2{$i}{$z}{$y}+$ColSumS0{$i}{$z}{$y}+$ColSumS1{$i }{$z}{$y}+$ColSumS2{
    $i}{$z}{$y};

    $RatioTotal = Input(3,$ColTotal,formstyle,ColTotal.$i.$z.$y,10);

    $Total = Input(3,$RatioAmt{$i}{$z}{$y},formstyle,Total.$i.$ z.$y,10);

    }
    else{
    $Pack0 = Input(3,0,formstyle,Pack0.$i.$z.$y,10);
    $Pack1 = Input(3,0,formstyle,Pack1.$i.$z.$y,10);
    $Pack2 = Input(3,0,formstyle,Pack2.$i.$z.$y,10);
    $Singles0 = Input(3,$RatioAmt{$i}{$z}{$y},formstyle,Singles0.$ i.$z.$y,10);
    $Singles1 = Input(3,0,formstyle,Singles1.$i.$z.$y,10);
    $Singles2 = Input(3,0,formstyle,Singles2.$i.$z.$y,10);
    $Total = Input(3,$RatioAmt{$i}{$z}{$y},formstyle,Total.$i.$ z.$y,10);
    $RatioTotal = Input(3,0,formstyle,ColTotal.$i.$z.$y,10);
    }
    //Save Input Boxes for later
    $P_In0 = $P_In0.$Pack0;
    $P_In1 = $P_In1.$Pack1;
    $P_In2 = $P_In2.$Pack2;
    $S_In0 = $S_In0.$Singles0;
    $S_In1 = $S_In1.$Singles1;
    $S_In2 = $S_In2.$Singles2;
    $Total_In = $Total_In.$Total;
    $RatioTotal_In = $RatioTotal_In.$RatioTotal;
    }
    $RatioPacksOrdered =
    $ColourSize.'<br>'.$fldHeaderR.'<br>'.$P_In0.'<br> '.$P_In1.'<br>'.$P_In2.'<br>'.$S_In0.'<br>'.$S_In1 .'<br>'.$S_In2.'<br>
    '.$RatioTotal_In.'<br>'.$Total_In.'<br>';
    //Pass to display variable
    $fldfldRatioPacksOrdered = $fldfldRatioPacksOrdered.$RatioPacksOrdered.'<br>' ;
    }
    }


    David Guest

  2. Similar Questions and Discussions

    1. #39713 [NEW]: Static variables defined in static methods duplicated in derived classes
      From: paul at digitalbacon dot us Operating system: Linux, Mac OS X 10.4, Windows XP PHP version: 5.2.0 PHP Bug Type: ...
    2. #39254 [NEW]: Refcount error with static variables and object references
      From: benoit dot heinrich at swisscom dot com Operating system: Linux PHP version: 4.4.4 PHP Bug Type: Class/Object related...
    3. #39254 [Opn->Fbk]: Refcount error with static variables and object references
      ID: 39254 Updated by: tony2001@php.net Reported By: benoit dot heinrich at swisscom dot com -Status: Open...
    4. #39048 [NEW]: Static variables and instantiated classes. private static doesn't work.
      From: matti at nitro dot fi Operating system: * PHP version: 5.1.6 PHP Bug Type: Scripting Engine problem Bug description: ...
    5. Problem with static variables
      Hi, I've got a boolean static variable defined in a forms OnLoad event and set to True. I then call a private sub which looks at the value for...
  3. #2

    Default Replacing code based on static variables to variable variables.

    Can anyone give me some help or tips in converting this code to take 2 variables that will specify the number of Pack
    type lines and the number of Single type lines. We use it to create a web page that allows us to split a garment
    delivery over multiple dates and and to specify the number and size of garments in a pack and the number and size of
    individual garments in the delivery. 3 of each has been enough until now. However we are finding new customers that want
    it spread over as many as 5 to 8 of each type pack and single.

    Everything is stored in an array $RPack.
    Easy to do as i new there were only ever goung to be 6 lines.

    $maxC is the number of colours available (usually 3)
    $maxR is the number of lengths each colour is available (usually 3)
    $maxH is the number of sizes each length is available in. (Between 8 & 14)

    Input() is a function for drawing HTML input boxes of the format

    Input (Size,Value,Class,Name,Maxlength,Readonly)

    I think what I need is to use variable variables but I am having a hard time getting my head around it so any tips and
    advice would be very gratefully received.

    // Create Data Entry, Boxes for Amt,Qty Total and Date
    for ($z=0; $z<$maxC; $z++){
    for ($y=0; $y<$maxR; $y++){
    //Set Temp variables to 0 or ""
    $ThisColour = "";
    $ThisRange = "";
    $ColourSize="";
    $P_In0="";
    $P_In1="";
    $P_In2="";
    $S_In0="";
    $S_In1="";
    $S_In2="";
    $Total_In="";
    $RatioTotal_In="";
    $LineAmt0 = 0;
    $LineAmt1 = 0;
    $LineAmt2 = 0;
    $LineAmtS0 = 0;
    $LineAmtS1 = 0;
    $LineAmtS2 = 0;
    $ColourSize = Input(8,$RatioColours{$z}.' '.$RatioRange{$y};,formstyle,Colour_Size,10);

    for ($i=0; $i<$maxH; $i++){
    // Check already an entry if so use it, if not add default order line to singles1 and set rest to 0
    if($fldfldMDA==1){

    $Pack0 = Input(3,$RPack[0]{$i}{$z}{$y},formstyle,Pack0.$i.$z.$y,10);
    $LineAmt0 = $LineAmt0 + $RPack[0]{$i}{$z}{$y};
    $ColSumP0{$i}{$z}{$y} = ($RPack[0]{$i}{$z}{$y}*$RPack[0]{$Qty}{$z}{$y});

    $Pack1 = Input(3,$RPack[1]{$i}{$z}{$y},formstyle,Pack1.$i.$z.$y,10);
    $LineAmt1 = $LineAmt1 + $RPack[1]{$i}{$z}{$y};
    $ColSumP1{$i}{$z}{$y} = ($RPack[1]{$i}{$z}{$y}*$RPack[1]{$Qty}{$z}{$y});

    $Pack2 = Input(3,$RPack[2]{$i}{$z}{$y},formstyle,Pack2.$i.$z.$y,10);
    $LineAmt2 = $LineAmt2 + $RPack[2]{$i}{$z}{$y};
    $ColSumP2{$i}{$z}{$y} = ($RPack[2]{$i}{$z}{$y}*$RPack[2]{$Qty}{$z}{$y});

    $Singles0 = Input(3,$RPack[3]{$i}{$z}{$y},formstyle,Singles0.$i.$z.$y,10);
    $LineAmtS0 = $LineAmtS0 + $RPack[3]{$i}{$z}{$y};
    $ColSumS0{$i}{$z}{$y} = ($RPack[3]{$i}{$z}{$y}*$RPack[3]{$Qty}{$z}{$y});

    $Singles1 = Input(3,$RPack[4]{$i}{$z}{$y},formstyle,Singles1.$i.$z.$y,10);
    $LineAmtS1 = $LineAmtS1 + $RPack[4]{$i}{$z}{$y};
    $ColSumS1{$i}{$z}{$y} = ($RPack[4]{$i}{$z}{$y}*$RPack[4]{$Qty}{$z}{$y});

    $Singles2 = Input(3,$RPack[5]{$i}{$z}{$y},formstyle,Singles2.$i.$z.$y,10);
    $LineAmtS2 = $LineAmtS2 + $RPack[5]{$i}{$z}{$y};
    $ColSumS2{$i}{$z}{$y} = ($RPack[5]{$i}{$z}{$y}*$RPack[5]{$Qty}{$z}{$y});

    $ColTotal =
    $ColSumP0{$i}{$z}{$y}+$ColSumP1{$i}{$z}{$y}+$ColSu mP2{$i}{$z}{$y}+$ColSumS0{$i}{$z}{$y}+$ColSumS1{$i }{$z}{$y}+$ColSumS2{
    $i}{$z}{$y};

    $RatioTotal = Input(3,$ColTotal,formstyle,ColTotal.$i.$z.$y,10);

    $Total = Input(3,$RatioAmt{$i}{$z}{$y},formstyle,Total.$i.$ z.$y,10);

    }
    else{
    $Pack0 = Input(3,0,formstyle,Pack0.$i.$z.$y,10);
    $Pack1 = Input(3,0,formstyle,Pack1.$i.$z.$y,10);
    $Pack2 = Input(3,0,formstyle,Pack2.$i.$z.$y,10);
    $Singles0 = Input(3,$RatioAmt{$i}{$z}{$y},formstyle,Singles0.$ i.$z.$y,10);
    $Singles1 = Input(3,0,formstyle,Singles1.$i.$z.$y,10);
    $Singles2 = Input(3,0,formstyle,Singles2.$i.$z.$y,10);
    $Total = Input(3,$RatioAmt{$i}{$z}{$y},formstyle,Total.$i.$ z.$y,10);
    $RatioTotal = Input(3,0,formstyle,ColTotal.$i.$z.$y,10);
    }
    //Save Input Boxes for later
    $P_In0 = $P_In0.$Pack0;
    $P_In1 = $P_In1.$Pack1;
    $P_In2 = $P_In2.$Pack2;
    $S_In0 = $S_In0.$Singles0;
    $S_In1 = $S_In1.$Singles1;
    $S_In2 = $S_In2.$Singles2;
    $Total_In = $Total_In.$Total;
    $RatioTotal_In = $RatioTotal_In.$RatioTotal;
    }
    $RatioPacksOrdered =
    $ColourSize.'<br>'.$fldHeaderR.'<br>'.$P_In0.'<br> '.$P_In1.'<br>'.$P_In2.'<br>'.$S_In0.'<br>'.$S_In1 .'<br>'.$S_In2.'<br>
    '.$RatioTotal_In.'<br>'.$Total_In.'<br>';
    //Pass to display variable
    $fldfldRatioPacksOrdered = $fldfldRatioPacksOrdered.$RatioPacksOrdered.'<br>' ;
    }
    }




    David Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139