*/$match = "match";
//database private stuff here
/*$query ="SELECT AVG(`item`), AVG(`item1`), AVG(`item2`), AVG(`item3`),AVG(`item4`), AVG(`item5`), AVG(`item6`) FROM Vains_test1 WHERE mood = 'happy'";*//*$query="SELECT AVG(item), AVG (item1), AVG(item2), AVG(item3), AVG(item4), AVG(item5), AVG(item6) FROM Vains_test1 where mood = 'happy'";*/$sum;$sum1; $sum2; $sum3; $sum4; $sum5; $sum6; $sum7; $sum8; $sum9; $sum10; $sum11; $sum12; $sum13; $sum14; $sum15; $sum16; $sum17;$sum18; $sum19; $sum20; $sum21; $sum22; $sum23; $sum24;
$query="SELECT item, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18, item19, item20, item21, item22, item23, item24 FROM Vains_test1 where mood = 'happy'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();$arrA = array();echo "
";$spe;$i=0;while ($i < $num) {
$item=mysql_result($result,$i,"item");$item1=mysql_result($result,$i,"item1");$item2=mysql_result($result,$i,"item2");$item3=mysql_result($result,$i,"item3");$item4=mysql_result($result,$i,"item4");$item5=mysql_result($result,$i,"item5");$item6=mysql_result($result,$i,"item6");$item7=mysql_result($result,$i,"item7");$item8=mysql_result($result,$i,"item8");$item9=mysql_result($result,$i,"item9");$item10=mysql_result($result,$i,"item10");$item11=mysql_result($result,$i,"item11");$item12=mysql_result($result,$i,"item12");$item13=mysql_result($result,$i,"item13");$item14=mysql_result($result,$i,"item14");$item15=mysql_result($result,$i,"item15");$item16=mysql_result($result,$i,"item16");$item17=mysql_result($result,$i,"item17");$item18=mysql_result($result,$i,"item18");$item19=mysql_result($result,$i,"item19");$item20=mysql_result($result,$i,"item20");$item21=mysql_result($result,$i,"item21");$item22=mysql_result($result,$i,"item22");$item23=mysql_result($result,$i,"item23");$item24=mysql_result($result,$i,"item24");
//echo "Item :$item
item2: $item
Item3: $item
item4: $item
item5: $item
item6: $item
";//echo "Item :$item";//now work out average for item
$sum += $item;$sum1 += $item1;$sum2 += $item2;$sum3 += $item3;$sum4 += $item4;$sum5 += $item5;$sum6 += $item6;$sum7 += $item7;$sum8 += $item8;$sum9 += $item9;$sum10 += $item10;$sum11 += $item11;$sum12 += $item12;$sum13 += $item13;$sum14 += $item14;$sum15 += $item15;$sum16 += $item16;$sum17 += $item17;$sum18 += $item18;$sum19 += $item19;$sum20 += $item20;$sum21 += $item21;$sum22 += $item22;$sum23 += $item23;$sum24 += $item24;$i++;}//echo $sum;//echo "num :$num";//$iavg = $sum/$num;//echo "$iavg";$item_avg = averager($sum,$num);$item1_avg = averager($sum1,$num);$item2_avg = averager($sum2,$num);$item3_avg = averager($sum3,$num);$item4_avg = averager($sum4,$num);$item5_avg = averager($sum5,$num);$item6_avg = averager($sum6,$num);$item7_avg = averager($sum7,$num);$item8_avg = averager($sum8,$num);$item9_avg = averager($sum9,$num);$item10_avg = averager($sum10,$num);$item11_avg = averager($sum11,$num);$item12_avg = averager($sum12,$num);$item13_avg = averager($sum13,$num);$item14_avg = averager($sum14,$num);$item15_avg = averager($sum15,$num);$item16_avg = averager($sum16,$num);$item17_avg = averager($sum17,$num);$item18_avg = averager($sum18,$num);$item19_avg = averager($sum19,$num);$item20_avg = averager($sum20,$num);$item21_avg = averager($sum21,$num);$item22_avg = averager($sum22,$num);$item23_avg = averager($sum23,$num);$item24_avg = averager($sum24,$num);/*echo "$item_avg";echo "$item1_avg";echo "$item2_avg";echo "$item3_avg";echo "$item4_avg";echo "$item5_avg";echo "$item6_avg";echo "$item7_avg";echo "$item8_avg";echo "$item9_avg";echo "$item10_avg";echo "$item11_avg";echo "$item12_avg";echo "$item13_avg";echo "$item14_avg";echo "$item15_avg";echo "$item16_avg";echo "$item17_avg";echo "$item18_avg";echo "$item19_avg";echo "$item20_avg";echo "$item21_avg";echo "$item22_avg";echo "$item23_avg";echo "$item24_avg";echo "----";*///
//
/*$maxer = max($item_avg, $item1_avg, $item2_avg, $item3_avg, $item4_avg);echo $maxer;if($maxer == $item4_avg){
echo " Item3 is max-"; }
*/
//order averages highest first/*$array_count=count($array); for($i=1;$i<=$array_count;$i++){$max_val[$i]=max_key($array);
$view=$array[$max_val[$i]];
unset($array[$max_val[$i]]);
print $view." ".$i."
"; // }
*/$array = array($item_avg, $item1_avg, $item2_avg, $item3_avg, $item4_avg, $item5_avg, $item6_avg, $item7_avg, $item8_avg, $item9_avg, $item10_avg, $item11_avg, $item12_avg, $item13_avg, $item14_avg, $item15_avg, $item16_avg, $item17_avg, $item18_avg, $item19_avg, $item20_avg, $item21_avg, $item22_avg, $item23_avg, $item24_avg);
$myFile = "testFile.txt";$fh = fopen($myFile, 'w') or die("can't open file");
//order averages highest first$array_count=count($array); for($i=1;$i<=$array_count;$i++){$max_val[$i]=max_key($array);
$view=$array[$max_val[$i]];
////get first 10 in an array
//try printing view to txt then getting back into array
////
unset($array[$max_val[$i]]);
//print $view." ".$i."
"; //
//fwrite($fh,$view." ".$i.""); $stringData = "\n"; fwrite($fh,$stringData); fwrite($fh,$view);
}
fclose($fh);
//////////////////////////////////////////
$line_array = file("testFile.txt");echo "
";
//echo $line_array[13];//echo "item13:
";//echo $item13_avg;
(string)$top1 = $line_array[1];(string)$top2 = $line_array[2];(string)$top3 = $line_array[3];(string)$top4 = $line_array[4];(string)$top5 = $line_array[5];(string)$top6 = $line_array[6];(string)$top7 = $line_array[7];(string)$top8 = $line_array[8];(string)$top9 = $line_array[9];(string)$top10 = $line_array[10];
echo "TOP 10
";//echo $top10;
(string)$it = $item1_avg;(string)$it2 = $item2_avg;(string)$it3 = $item4_avg;(string)$it4 = $item4_avg;(string)$it5 = $item5_avg;(string)$it6 = $item6_avg;(string)$it7 = $item7_avg;(string)$it8 = $item8_avg;(string)$it9 = $item9_avg;(string)$it10 = $item10_avg;(string)$it11 = $item11_avg;(string)$it12 = $item12_avg;(string)$it13 = $item13_avg;(string)$it14 = $item14_avg;(string)$it15 = $item15_avg;(string)$it16 = $item16_avg;(string)$it17 = $item17_avg;(string)$it18 = $item18_avg;(string)$it19 = $item19_avg;(string)$it20 = $item20_avg;(string)$it21 = $item21_avg;(string)$it22 = $item22_avg;(string)$it23 = $item23_avg;(string)$it24 = $item24_avg;// echo "$top1:"; echo "
";echo round($top1, 2); echo "
"; //echo "
$it13:";echo round($it10, 2);echo "
" ; $tes = 3;echo round(tes, 2);echo "
" ;
//ok so rounding is the soution to the problem if(round($line_array[1]) === round($item10_avg)){ echo $match; echo "Matchwwww
";
}
//now put on a loop//but rounding angerous for whole numbers such as 4//try PHP_ROUND_HALF_UP??? if(round($top1) === round($it10)){ echo $match; echo "Match
";
}
echo "___+___
"; echo strcasecmp($top1, $it10); echo "___+___
"; if (!strcasecmp($top1, $it10)){ print "The email addresses are identical!";
}
/*if ($top1 == $it10) echo "OK-1";//if (strcmp($ff,trim($numn2)) == 0) echo "OK-4"; //works!if (strcmp( $top1,trim($it10)) == 0) echo "OK-it is"; //doesnt workif (strcmp($top1, trim($it10) )== 0) echo "OK-3";
if (strcmp(trim($top1), trim($it13)) == 0) { echo "strings are equal"; } else { echo "string are not equal"; } */
//strcmp Returns <> 0 if str1 is greater than str2, and 0 if they are equal. //IN PHP FLOAT EQUALITY DOESNT WORK
echo "
";/////////////////////////////////////////////function max_key($array) {foreach ($array as $key => $val) {if ($val == max($array)) return $key;
}
}
////////////////////////////////////////////function averager($x,$y){$avg= $x/$y;return $avg;}
/////////////////////*$arrA = array();
$arrA ["$item"] = $item_avg;$arrA ["$item2"] = $item2_avg;$arrA ["$item3"] = $item3_avg;$arrA ["$item4"] = $item4_avg;*///echo "look item average is".$item_avg. "
";
/*$file = fopen("testFile.txt", "r") or exit("Unable to open file!");//Output a line of the file until the end is reachedwhile(!feof($file)) { // echo fgets($file). "
"; }
*/
$file = fopen("testFile.txt", "r") or exit("Unable to open file!");//Output a line of the file until the end is reachedfor($i=1;$i<=11;$i++){
echo fgets($file). "
"; }
fclose($file);
//so we get top ten//put in database then test for matches against each item's avg_score?
//////////
?>