Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    32
    Thanks
    5
    Thanked 0 Times in 0 Posts

    While Loop Problem

    Hello,

    I have a interesting issue that is most likely a easy fix.

    When I send a URL endcode to Script 1 it works great.

    When I loop the $grp variable using a while/endwhile command (Script 2), it displays 4 sets of the calculations, but the results of the calculations are all the same.

    I am not sure if the fix is to destroy the array $answer at the end of the calculations. If that seems logical, then how would I do that?

    Script 1
    PHP Code:
    $grp $_GET["group"];
    include 
    '/home/jlimited/public_html/thesis/.db.php';
    $completed mysql_query("SELECT * FROM participants WHERE age!='999' AND complete='1'")
             or die(
    "Invalid query: " mysql_error());
    $pcount mysql_num_rows($completed);

    $pid 1;
    while(
    $row mysql_fetch_array($completed)){
         foreach( 
    $row AS $key => $val ){
            $
    $key stripslashes$val );
        }
    $sub mysql_query("SELECT * FROM answers WHERE sid='$sid' AND grpvalue='$grp'")
             or die(
    "Invalid query: " mysql_error());
    $qcount mysql_num_rows($sub);
    $qid 1;
    while(
    $items mysql_fetch_array($sub)){
         foreach( 
    $items AS $key => $val ){
            $
    $key stripslashes$val );
        }
    $answer[$qid][$pid] = $answervalue;
    $qid++;
    }
    $pid++;

    Script 2
    PHP Code:
    include '/home/jlimited/public_html/thesis/.db.php';
    $completed mysql_query("SELECT * FROM participants WHERE age!='999' AND complete='1'")
             or die(
    "Invalid query: " mysql_error());
    $pcount mysql_num_rows($completed);

    $grp 1;
    while (
    $grp <= 4):
    $pid 1;
    while(
    $row mysql_fetch_array($completed)){
         foreach( 
    $row AS $key => $val ){
            $
    $key stripslashes$val );
        }
    $sub mysql_query("SELECT * FROM answers WHERE sid='$sid' AND grpvalue='$grp'")
             or die(
    "Invalid query: " mysql_error());
    $qcount mysql_num_rows($sub);
    $qid 1;
    while(
    $items mysql_fetch_array($sub)){
         foreach( 
    $items AS $key => $val ){
            $
    $key stripslashes$val );
        }
    $answer[$qid][$pid] = $answervalue;
    $qid++;
    }
    $pid++;
    }

    echo 
    $qcount."<br>";
    echo 
    calpha($qcount,$pcount,$answer)."<br>";
    echo 
    mean($qcount,$pcount,$answer)."<br>";
    echo 
    sd($qcount,$pcount,$answer)."<br><br>";
    $grp++;
    endwhile; 
    Thanks
    Jlimited

  • #2
    New to the CF scene
    Join Date
    Feb 2007
    Location
    Bisbee, Arizona
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    That is a tough one.
    I have e-mailed a co worker of mine who is a coder from Northrop Grumman. I will have an answer withing 24 hours.
    Please send me an e-mail at theoneandonlyqueen2007@hotmail.com and I will respond with an answer. I am a technical systems analyst, I don't do most code, however, I enlisted for this site to help people test their code and software...so yeah...anyways,
    Just send me an e-mail. I am sure I will be able to help.

    Thanks- TQ


  •  

    Posting Permissions

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