...

View Full Version : While Loop Problem



jlimited
02-26-2007, 01:41 AM
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


$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


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

thequeen2007
02-26-2007, 05:46 AM
;) 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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum