Results 1 to 4 of 4

Thread: php for loops

  1. #1
    scoutt
    Guest

    php for loops

    ok I need help figuring this loop crap out.

    I have a select that is made from a loop. no problem there. once the select it selected then it make inputs from how many was selected form the select statement. no problem there. my problem is on the <inputs> tages. the name I have to use is an array.. something like this name= something[].

    now when the values are inputed into the input statements how do I put them in another loop?
    PHP Code:
    function multiresist($i){
    $myCalculator = new ScientificCalculator();
      
    $vr = array("R1","R2","R3","R4","R5","R6","R7","R8");
      
    $vs = array("vr1","vr2","vr3","vr4","vr5","vr6","vr7","vr8");
            
    //$vr1 = $myCalculator->multiply($i,$r1);
            //$vr2 = $myCalculator->multiply($i,$r2);
            //$vr3 = $myCalculator->multiply($i,$r3);
            //$vr4 = $myCalculator->multiply($i,$r4);
            //$vr5 = $myCalculator->multiply($i,$r5);
            //$vr6 = $myCalculator->multiply($i,$r6);
            //$vr7 = $myCalculator->multiply($i,$r7);
            //$vr8 = $myCalculator->multiply($i,$r8);
             
    for ($counter=1$counter<8$counter++){
                 
    $vs[$counter] = $myCalculator->multiply($i,$resistor[$counter]);
                 echo 
    "<br><b>$vr[$counter]</b> = $vs[$counter]";
                 } 
    I looked in the source of the page and the name for the all the inputs is resistor[]. now I know that nothing is there yet as there is nothing in the text box. put once there get occupied how do I get them out into the above code?

    now the loop on the bottom works but I get R1=0. so I know the values from the text inputs aren't getting up to it. duh! I know that I ain't even calling it yet, that is where I am stuck.

    the commented lines is what I need to make into an loop/array.
    I have half of it working but can't the values from the text boxes.

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Dude-man, I can't understand what you are saying! You need to use some puncuation and work on your grammar.

    Aside from that, why does your for loop start with $counter = 1 and not 0?

    Does PHP support foreach? If so, use it.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3
    scoutt
    Guest
    sorry, I get to typing fast and I make a lot of errors. sometimes I don't catch all of them. the counter was a mistake, I had to change it to 0 which you are correct.

    as far as php using the foreach, I don't think so. I will look into that.

  4. #4
    scoutt
    Guest
    don't worry about it. I go tit.
    PHP Code:
    for ($counter=0$counter<$times$counter++){
                 
    $rt $resistors[$counter];
                 
    $vrt $myCalculator->multiply($i,$rt); 
    actually it was pretty easy now that I think about it.

Posting Permissions

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



Click Here to Expand Forum to Full Width