Jump to content

How to make simple if repeat in looping?


deib97

Recommended Posts

I was hard code to make if condition until like seem. But its to hard to write.

if ($lebar == 41) {
                $x = 1;
            } else if ($lebar == 42) {
                $x = 2;
            } else if ($lebar == 43) {
                $x = 3;
            } else if ($lebar == 44) {
                $x = 4;
            } else if ($lebar == 45) {
                $x = 5;
				.....
            } else if ($lebar == 490) {
                $x = 450;
            }

How to make it simple with looping or any clue? 

Link to comment
Share on other sites

 if (lebar == 41) {
                x = 1;
            } else if (lebar == 42) {
                x = 2;
            } else if (lebar == 43) {
                x = 3;
            } else if (lebar == 44) {
                x = 4;
            } else if (lebar == 45) {
                x = 5;
            } else if (lebar == 46) {
                x = 6;
            } else if (lebar == 47) {
                x = 7;
            } else if (lebar == 48) {
                x = 8;
            } else if (lebar == 49) {
                x = 9;
            } else if (lebar == 50) {
                x = 10;
            } else if (lebar == 51) {
                x = 11;
            } else if (lebar == 52) {
                x = 12;
            } else if (lebar == 53) {
                x = 13;
            } else if (lebar == 54) {
                x = 14;
            } else if (lebar == 55) {
                x = 15;
            } else if (lebar == 56) {
                x = 16;
            } else if (lebar == 57) {
                x = 17;
            } else if (lebar == 58) {
                x = 18;
            } else if (lebar == 59) {
                x = 19;
            } else if (lebar == 60) {
                x = 20;
            } else if (lebar == 61) {
                x = 21;
            } else if (lebar == 62) {
                x = 22;
            } else if (lebar == 63) {
                x = 23;
            } else if (lebar == 64) {
                x = 24;
            } else if (lebar == 65) {
                x = 25;
            } else if (lebar == 66) {
                x = 26;
            } else if (lebar == 67) {
                x = 27;
            } else if (lebar == 68) {
                x = 28;
            } else if (lebar == 69) {
                x = 29;
            } else if (lebar == 70) {
                x = 30;
            } else if (lebar == 71) {
                x = 31;
            } else if (lebar == 72) {
                x = 32;
            } else if (lebar == 73) {
                x = 33;
            } else if (lebar == 74) {
                x = 34;
            } else if (lebar == 75) {
                x = 35;
            } else if (lebar == 76) {
                x = 36;
            } else if (lebar == 77) {
                x = 37;
            } else if (lebar == 78) {
                x = 38;
            } else if (lebar == 79) {
                x = 39;
            } else if (lebar == 80) {
                x = 40;
            } else if (lebar == 81) {
                x = 41;
            } else if (lebar == 82) {
                x = 42;
            } else if (lebar == 83) {
                x = 43;
            } else if (lebar == 84) {
                x = 44;
            } else if (lebar == 85) {
                x = 45;
            } else if (lebar == 86) {
                x = 46;
            } else if (lebar == 87) {
                x = 47;
            } else if (lebar == 88) {
                x = 48;
            } else if (lebar == 89) {
                x = 49;
            } else if (lebar == 90) {
                x = 50;
            } else if (lebar == 91) {
                x = 51;
            } else if (lebar == 92) {
                x = 52;
            } else if (lebar == 93) {
                x = 53;
            } else if (lebar == 94) {
                x = 54;
            } else if (lebar == 95) {
                x = 55;
            } else if (lebar == 96) {
                x = 56;
            } else if (lebar == 97) {
                x = 57;
            } else if (lebar == 98) {
                x = 58;
            } else if (lebar == 99) {
                x = 59;
            } else if (lebar == 100) {
                x = 60;
            } else if (lebar == 101) {
                x = 61;
            } else if (lebar == 102) {
                x = 62;
            } else if (lebar == 103) {
                x = 63;
            } else if (lebar == 104) {
                x = 64;
            } else if (lebar == 105) {
                x = 65;
            } else if (lebar == 106) {
                x = 66;
            } else if (lebar == 107) {
                x = 67;
            } else if (lebar == 108) {
                x = 68;
            } else if (lebar == 109) {
                x = 69;
            } else if (lebar == 110) {
                x = 70;
            } else if (lebar == 111) {
                x = 71;
            } else if (lebar == 112) {
                x = 72;
            } else if (lebar == 113) {
                x = 73;
            } else if (lebar == 114) {
                x = 74;
            } else if (lebar == 115) {
                x = 75;
            } else if (lebar == 116) {
                x = 76;
            } else if (lebar == 117) {
                x = 77;
            } else if (lebar == 118) {
                x = 78;
            } else if (lebar == 119) {
                x = 79;
            } else if (lebar == 120) {
                x = 80;
            } else if (lebar == 121) {
                x = 81;
            } else if (lebar == 122) {
                x = 82;
            } else if (lebar == 123) {
                x = 83;
            } else if (lebar == 124) {
                x = 84;
            } else if (lebar == 125) {
                x = 85;
            } else if (lebar == 126) {
                x = 86;
            } else if (lebar == 127) {
                x = 87;
            } else if (lebar == 128) {
                x = 88;
            } else if (lebar == 129) {
                x = 89;
            } else if (lebar == 130) {
                x = 90;
            } else if (lebar == 131) {
                x = 91;
            } else if (lebar == 132) {
                x = 92;
            } else if (lebar == 133) {
                x = 93;
            } else if (lebar == 134) {
                x = 94;
            } else if (lebar == 135) {
                x = 95;
            } else if (lebar == 136) {
                x = 96;
            } else if (lebar == 137) {
                x = 97;
            } else if (lebar == 138) {
                x = 98;
            } else if (lebar == 139) {
                x = 99;
            } else if (lebar == 140) {
                x = 100;
            } else if (lebar == 141) {
                x = 101;
            } else if (lebar == 142) {
                x = 102;
            } else if (lebar == 143) {
                x = 103;
            } else if (lebar == 144) {
                x = 104;
            } else if (lebar == 145) {
                x = 105;
            } else if (lebar == 146) {
                x = 106;
            } else if (lebar == 147) {
                x = 107;
            } else if (lebar == 148) {
                x = 108;
            } else if (lebar == 149) {
                x = 109;
            } else if (lebar == 150) {
                x = 110;
            } else if (lebar == 151) {
                x = 111;
            } else if (lebar == 152) {
                x = 112;
            } else if (lebar == 153) {
                x = 113;
            } else if (lebar == 154) {
                x = 114;
            } else if (lebar == 155) {
                x = 115;
            } else if (lebar == 156) {
                x = 116;
            } else if (lebar == 157) {
                x = 117;
            } else if (lebar == 158) {
                x = 118;
            } else if (lebar == 159) {
                x = 119;
            } else if (lebar == 160) {
                x = 120;
            } else if (lebar == 161) {
                x = 121;
            } else if (lebar == 162) {
                x = 122;
            } else if (lebar == 163) {
                x = 123;
            } else if (lebar == 164) {
                x = 124;
            } else if (lebar == 165) {
                x = 125;
            } else if (lebar == 166) {
                x = 126;
            } else if (lebar == 167) {
                x = 127;
            } else if (lebar == 168) {
                x = 128;
            } else if (lebar == 169) {
                x = 129;
            } else if (lebar == 170) {
                x = 130;
            } else if (lebar == 171) {
                x = 131;
            } else if (lebar == 172) {
                x = 132;
            } else if (lebar == 173) {
                x = 133;
            } else if (lebar == 174) {
                x = 134;
            } else if (lebar == 175) {
                x = 135;
            } else if (lebar == 176) {
                x = 136;
            } else if (lebar == 177) {
                x = 137;
            } else if (lebar == 178) {
                x = 138;
            } else if (lebar == 179) {
                x = 139;
            } else if (lebar == 180) {
                x = 140;
            } else if (lebar == 181) {
                x = 141;
            } else if (lebar == 182) {
                x = 142;
            } else if (lebar == 183) {
                x = 143;
            } else if (lebar == 184) {
                x = 144;
            } else if (lebar == 185) {
                x = 145;
            } else if (lebar == 186) {
                x = 146;
            } else if (lebar == 187) {
                x = 147;
            } else if (lebar == 188) {
                x = 148;
            } else if (lebar == 189) {
                x = 149;
            } else if (lebar == 190) {
                x = 150;
            } else if (lebar == 191) {
                x = 151;
            } else if (lebar == 192) {
                x = 152;
            } else if (lebar == 193) {
                x = 153;
            } else if (lebar == 194) {
                x = 154;
            } else if (lebar == 195) {
                x = 155;
            } else if (lebar == 196) {
                x = 156;
            } else if (lebar == 197) {
                x = 157;
            } else if (lebar == 198) {
                x = 158;
            } else if (lebar == 199) {
                x = 159;
            } else if (lebar == 200) {
                x = 160;
            } else if (lebar == 201) {
                x = 161;
            } else if (lebar == 202) {
                x = 162;
            } else if (lebar == 203) {
                x = 163;
            } else if (lebar == 204) {
                x = 164;
            } else if (lebar == 205) {
                x = 165;
            } else if (lebar == 206) {
                x = 166;
            } else if (lebar == 207) {
                x = 167;
            } else if (lebar == 208) {
                x = 168;
            } else if (lebar == 209) {
                x = 169;
            } else if (lebar == 210) {
                x = 170;
            } else if (lebar == 211) {
                x = 171;
            } else if (lebar == 212) {
                x = 172;
            } else if (lebar == 213) {
                x = 173;
            } else if (lebar == 214) {
                x = 174;
            } else if (lebar == 215) {
                x = 175;
            } else if (lebar == 216) {
                x = 176;
            } else if (lebar == 217) {
                x = 177;
            } else if (lebar == 218) {
                x = 178;
            } else if (lebar == 219) {
                x = 179;
            } else if (lebar == 220) {
                x = 180;
            } else if (lebar == 221) {
                x = 181;
            } else if (lebar == 222) {
                x = 182;
            } else if (lebar == 223) {
                x = 183;
            } else if (lebar == 224) {
                x = 184;
            } else if (lebar == 225) {
                x = 185;
            } else if (lebar == 226) {
                x = 186;
            } else if (lebar == 227) {
                x = 187;
            } else if (lebar == 228) {
                x = 188;
            } else if (lebar == 229) {
                x = 189;
            } else if (lebar == 230) {
                x = 190;
            } else if (lebar == 231) {
                x = 191;
            } else if (lebar == 232) {
                x = 192;
            } else if (lebar == 233) {
                x = 193;
            } else if (lebar == 234) {
                x = 194;
            } else if (lebar == 235) {
                x = 195;
            } else if (lebar == 236) {
                x = 196;
            } else if (lebar == 237) {
                x = 197;
            } else if (lebar == 238) {
                x = 198;
            } else if (lebar == 239) {
                x = 199;
            } else if (lebar == 240) {
                x = 200;
            } else if (lebar == 241) {
                x = 201;
            } else if (lebar == 242) {
                x = 202;
            } else if (lebar == 243) {
                x = 203;
            } else if (lebar == 244) {
                x = 204;
            } else if (lebar == 245) {
                x = 205;
            } else if (lebar == 246) {
                x = 206;
            } else if (lebar == 247) {
                x = 207;
            } else if (lebar == 248) {
                x = 208;
            } else if (lebar == 249) {
                x = 209;
            } else if (lebar == 250) {
                x = 210;
            } else if (lebar == 251) {
                x = 211;
            } else if (lebar == 252) {
                x = 212;
            } else if (lebar == 253) {
                x = 213;
            } else if (lebar == 254) {
                x = 214;
            } else if (lebar == 255) {
                x = 215;
            } else if (lebar == 256) {
                x = 216;
            } else if (lebar == 257) {
                x = 217;
            } else if (lebar == 258) {
                x = 218;
            } else if (lebar == 259) {
                x = 219;
            } else if (lebar == 260) {
                x = 220;
            } else if (lebar == 261) {
                x = 221;
            } else if (lebar == 262) {
                x = 222;
            } else if (lebar == 263) {
                x = 223;
            } else if (lebar == 264) {
                x = 224;
            } else if (lebar == 265) {
                x = 225;
            } else if (lebar == 266) {
                x = 226;
            } else if (lebar == 267) {
                x = 227;
            } else if (lebar == 268) {
                x = 228;
            } else if (lebar == 269) {
                x = 229;
            } else if (lebar == 270) {
                x = 230;
            } else if (lebar == 271) {
                x = 231;
            } else if (lebar == 272) {
                x = 232;
            } else if (lebar == 273) {
                x = 233;
            } else if (lebar == 274) {
                x = 234;
            } else if (lebar == 275) {
                x = 235;
            } else if (lebar == 276) {
                x = 236;
            } else if (lebar == 277) {
                x = 237;
            } else if (lebar == 278) {
                x = 238;
            } else if (lebar == 279) {
                x = 239;
            } else if (lebar == 280) {
                x = 240;
            } else if (lebar == 281) {
                x = 241;
            } else if (lebar == 282) {
                x = 242;
            } else if (lebar == 283) {
                x = 243;
            } else if (lebar == 284) {
                x = 244;
            } else if (lebar == 285) {
                x = 245;
            } else if (lebar == 286) {
                x = 246;
            } else if (lebar == 287) {
                x = 247;
            } else if (lebar == 288) {
                x = 248;
            } else if (lebar == 289) {
                x = 249;
            } else if (lebar == 290) {
                x = 250;
            } else if (lebar == 291) {
                x = 251;
            } else if (lebar == 292) {
                x = 252;
            } else if (lebar == 293) {
                x = 253;
            } else if (lebar == 294) {
                x = 254;
            } else if (lebar == 295) {
                x = 255;
            } else if (lebar == 296) {
                x = 256;
            } else if (lebar == 297) {
                x = 257;
            } else if (lebar == 298) {
                x = 258;
            } else if (lebar == 299) {
                x = 259;
            } else if (lebar == 300) {
                x = 260;
            } else if (lebar == 301) {
                x = 261;
            } else if (lebar == 302) {
                x = 262;
            } else if (lebar == 303) {
                x = 263;
            } else if (lebar == 304) {
                x = 264;
            } else if (lebar == 305) {
                x = 265;
            } else if (lebar == 306) {
                x = 266;
            } else if (lebar == 307) {
                x = 267;
            } else if (lebar == 308) {
                x = 268;
            } else if (lebar == 309) {
                x = 269;
            } else if (lebar == 310) {
                x = 270;
            } else if (lebar == 311) {
                x = 271;
            } else if (lebar == 312) {
                x = 272;
            } else if (lebar == 313) {
                x = 273;
            } else if (lebar == 314) {
                x = 274;
            } else if (lebar == 315) {
                x = 275;
            } else if (lebar == 316) {
                x = 276;
            } else if (lebar == 317) {
                x = 277;
            } else if (lebar == 318) {
                x = 278;
            } else if (lebar == 319) {
                x = 279;
            } else if (lebar == 320) {
                x = 280;
            } else if (lebar == 321) {
                x = 281;
            } else if (lebar == 322) {
                x = 282;
            } else if (lebar == 323) {
                x = 283;
            } else if (lebar == 324) {
                x = 284;
            } else if (lebar == 325) {
                x = 285;
            } else if (lebar == 326) {
                x = 286;
            } else if (lebar == 327) {
                x = 287;
            } else if (lebar == 328) {
                x = 288;
            } else if (lebar == 329) {
                x = 289;
            } else if (lebar == 330) {
                x = 290;
            } else if (lebar == 331) {
                x = 291;
            } else if (lebar == 332) {
                x = 292;
            } else if (lebar == 333) {
                x = 293;
            } else if (lebar == 334) {
                x = 294;
            } else if (lebar == 335) {
                x = 295;
            } else if (lebar == 336) {
                x = 296;
            } else if (lebar == 337) {
                x = 297;
            } else if (lebar == 338) {
                x = 298;
            } else if (lebar == 339) {
                x = 299;
            } else if (lebar == 340) {
                x = 300;
            }
            else {
                x = 450;
            }
48 minutes ago, deib97 said:

I must input / edit $lebar from 41 until 491 with value variable $x from 1 until 450.

 

Yes, i'm still copy paste long long code. hehe

Link to comment
Share on other sites

10 hours ago, deib97 said:

I must input edit $lebar from 41 until 491 with value variable $x from 1 until 450.

 

You don't seem to understand my question. You are asking how to solve your Attempted Solution to the Real problem. I want to know what the REAL problem is, not your approach to solving it. WHY are you doing this? Therein lies the REAL problem.

Link to comment
Share on other sites

Sorry if my question and my approach made you angry. I am making a calculator application to calculate tank volume and weight in kilograms(with Specific Gravity). This tank is shaped like a tube and cone in the excel table that I attached  (there is a picture). In my application there is an input field for entering the sounding level data. and count button.
If the level is <40 cm, the volume formula uses (0.33 * 3.14 * jari* jari * height / 1000) but if the level of souding shows a level> 40 cm, the volume formula is different. Details can be seen in the excel data that I attached.

I do not want to create an atmosphere of misunderstanding,I just want to get help if that is possible. If not, it's okay. I attach an link excel file, the application display file as a simulation of what I mean.
my excel. Look at column S to AE.

 

level if krg 40.png

level if lbh 40.png

Link to comment
Share on other sites

1 hour ago, deib97 said:

Sorry if my question and my approach made you angry. I am making a calculator application to calculate tank volume and weight in kilograms(with Specific Gravity). This tank is shaped like a tube and cone in the excel table that I attached  (there is a picture). In my application there is an input field for entering the sounding level data. and count button.
If the level is <40 cm, the volume formula uses (0.33 * 3.14 * jari* jari * height / 1000) but if the level of souding shows a level> 40 cm, the volume formula is different. Details can be seen in the excel data that I attached. 

I do not want to create an atmosphere of misunderstanding,I just want to get help if that is possible. If not, it's okay. I attach an link excel file, the application display file as a simulation of what I mean.
my excel. Look at column S to AE.

Great, this is exactly what I was referring to as the real problem. Now we can decide what the correct approach should be, whether it is your approach or something else. I was not angry. We just need to know what is really going on to provide the best answers for you.

Link to comment
Share on other sites

13 hours ago, deib97 said:

0.33 * 3.14 * jari* jari * height / 1000

What is the 1000 for?

What is the radius of the tank to give those results you posted? I am assuming you have something like this (where the cone height (HC) is 40cm

    |      |
    |      |
    |      |
    |______|
    |      |            |    cylinder  πR^2(h - HC)    h > HC (add cylinder)
    |      |            |
    |      |            |
    |---R--|             h
    \      /    |       |
     \    /     |       |         cone πR^2h/3          h <= HC
      \  /      HC      |
       \/       |       |

 

Edited by Barand
  • Like 1
Link to comment
Share on other sites

16 hours ago, Barand said:

What is the 1000 for?

What is the radius of the tank to give those results you posted? I am assuming you have something like this (where the cone height (HC) is 40cm


    |      |
    |      |
    |      |
    |______|
    |      |            |    cylinder  πR^2(h - HC)    h > HC (add cylinder)
    |      |            |
    |      |            |
    |---R--|             h
    \      /    |       |
     \    /     |       |         cone πR^2h/3          h <= HC
      \  /      HC      |
       \/       |       |

 

1000  for converting to volume. Yes, Barand. I do not allow entering input height many times. One time gives the number height on the stick level. I agree with you about cone height 40cm. Formulas cone + cylinder if height stick from manhole is open and > 40cm.

IMG_20190201_1446188888.jpg

Edited by deib97
Link to comment
Share on other sites

In the absence of a reply, I estimated the radius to be about 3.5m from that photo. This gives a table of volmes and weights based on that radius. Note the absence of if..., if..., if..., if...)

<?php
const R = 350;               // radius of tank   cm       NOTE: estimated - replace with actual radius
const HC = 40;               // cone height  cm
 
function tank_volume ($h)
{
    $k = M_PI * R**2 ;
    
    if ($h <= HC) {
        $vol = $k * $h / 3 ;
    }
    else {
        $vol =  $k * HC / 3  + $k * ($h - HC);
    }
    return $vol;
}

$results = [];
foreach (range(1,500) as $h) {
    $vol = tank_volume($h);
    $results[] = [ 'ht' => $h, 
                   'vol' =>  number_format($vol, 0),
                   'Kg' => number_format($vol/1000, 0)
                 ];
    
}
$chunks = array_chunk($results,100);
$output = '';
foreach ($chunks as $ch) {
    $output .= "<div class='output'>
        <table><tr><th>Height<?th><th>Volume (cc)</th><th>Kg</th></tr>
        ";
    foreach ($ch as $res) {
        $cls = $res['ht'] < 41 ? "class='cone'" : '';
        $output .= "<tr $cls><td>".join('</td><td>', $res)."</td></tr>\n";
    }
    $output .= "</table></div>\n";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)">
<title>Tank Volumes</title>
<meta name="author" content="Barand">
<link rel="shortcut icon"  href="">
<meta name="creation-date" content="02/01/2019">
<style type='text/css'>
    body {
        font-family: calibri, arial, sans-serif;
        font-size: 10pt;
    }
    #title {
        height: 50px;
        font-size: 24px;
        font-weight: 600;
        background-image: linear-gradient(#2DABE1, #FFFFFF);
        color: #FFF;
        padding: 15px;
    }
    .output {
        width: 300px;
        font-size: 20px;
        float: left;
        padding: 2px;
        border-right: 1px solid #BB9A21;
    }
    table {
        width: 100%;
        font-size: 10pt;
    }
    th {
        background-color: #BB9A21;
        color: #FFF;
        padding: 5px;
    }
    td {
        text-align: right;
        padding: 2px 5px;
    }
    .cone {
        background-color: #EEE;
    }
</style>
</head>
<body>
<div id='title'>Tank Volumes and Weights</div>
<?=$output?>
</body>
</html>

Sample output

partial_screenshot.png

  • Like 1
  • Great Answer 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.