Jump to content

does "array" same with "mysql_fetch_array"


abrew

Recommended Posts

hi again ,,, i need help again (as beginers) ,,, plizz

 

i'm going to run percentile function that i found by googling

it's work well with the example ,,, here's the script ;

 

require_once("../lib/Stat.class.php");

$stat = new Stat();

$data = array(12,34, 21, 14, 23, 56);

echo "data = ".$data."<br />";

echo "25th Percentile = ".$stat->percentile($data,25)."<br />";

echo "Median (50th percentile) = ".$stat->median($data)."<br />";

echo "95th Percentile = ".$stat->percentile($data,95)."<br />";

echo "quartile(25th, 50th, 75th percentile) = ".implode(", ", $stat->quartiles($data))."<br />";

 

but i need to use this function to calculate my data on database so i do like this

 

require_once("../lib/Stat.class.php");

$stat = new Stat();

$T10p = "SELECT MaxTemp FROM monthly_syn";

$T10pqres = mysql_query($T10p);

$data = mysql_fetch_array($T10pqres);

// $data = array(12,34, 21, 14, 23, 56);

echo "data = ".$data."<br />";

echo "25th Percentile = ".$stat->percentile($data,25)."<br />";

echo "Median (50th percentile) = ".$stat->median($data)."<br />";

echo "95th Percentile = ".$stat->percentile($data,95)."<br />";

echo "quartile(25th, 50th, 75th percentile) = ".implode(", ", $stat->quartiles($data))."<br />";

 

and the result is wrong ,,,

is that because of MYSQL_FETCH_ARRAY ,,, ???

i think mysql_fetch_array will get the same result as array  <this make me confuse>

 

please any idea ???

 

 

here's the stat.class.php ;

<?php

 

class Stat{

 

function median($data){

$median = $this->percentile($data,50);

return $median;

}

 

function percentile($data,$percentile){

if( 0 < $percentile && $percentile < 1 ) {

$p = $percentile;

}else if( 1 < $percentile && $percentile <= 100 ) {

$p = $percentile * .01;

}else {

return "";

}

$count = count($data);

$allindex = ($count-1)*$p;

$intvalindex = intval($allindex);

$floatval = $allindex - $intvalindex;

sort($data);

if(!is_float($floatval)){

$result = $data[$intvalindex];

}else {

if($count > $intvalindex+1)

$result = $floatval*($data[$intvalindex+1] - $data[$intvalindex]) + $data[$intvalindex];

else

$result = $data[$intvalindex];

}

return $result;

}

 

function quartiles($data) {

$q1 = $this->percentile($data,25);

$q2 = $this->percentile($data, 50);

$q3 = $this->percentile($data, 75);

$quartile = array ( '25' => $q1, '50' => $q2, '75' => $q3);

return $quartile;

}

 

}

?>

Link to comment
https://forums.phpfreaks.com/topic/264854-does-array-same-with-mysql_fetch_array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.