Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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