|
|
|
// sloppy but functional way to find the median in an ordered list
// connect to database
$link = mysql_connect("host","dbase","password");
$db = mysql_select_db("dbase", $link);
// select and retreive data
$sql = "SELECT * FROM table_name";
$sql_result = mysql_query($sql,$link);
$i=0;
while ($row = mysql_fetch_array($sql_result))
{
// load array with data from table
$test_data[] = $row["test_data"];
$i = $i + 1;
}
// sort the array
rsort($test_data);
for ( $count = 0; $count<$i; $count++)
echo "$test_data[$count] <br>";
mysql_free_result($sql_result);
$oe_value = count($test_data);
if ($oe_value % 2 == 0 )
{
$position = 1;
}
else
{
$position = 2;
}
if ($position == 2 )
{
$median = $test_data[(count($test_data)/2)];
}
else
{
$median= (($test_data[(count($test_data)/2)-1]) +
($test_data[(count($test_data)/2)]))/2;
}
// $median will either be the middle value in the array if the count is odd
// or the average of the center two numbers if the count is even
|
|
| How to load a query result into a PHP Array Categories : PHP, Databases, Arrays, MySQL | | | dynamic table columns Categories : PHP, HTML and PHP, Arrays, Databases, MySQL | | | This simple function will take a few arguments and easily set a associative array for each column in a result from a MySQL query Categories : Databases, PHP, MySQL, Arrays | | | create a grid out of <INPUT TYPE=TEXT> then saving to a database. Uses
a 'multi-dimension array', but not really as the array is just one big array
with the index of "[$i][$j]". Have a look at the code and you'll see what I
mean. Categories : PHP, MySQL, Arrays, Databases | | | Function for retrieving MySQL enum values into a PHP array.
Categories : PHP, Databases, MySQL, Arrays | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Sort the results from a SELECT query (any number of columns) into an array automatically. Categories : PHP, PHP Classes, Arrays, Databases, MySQL | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL | | | This functions makes it easy to use session-variables known from ASP. With one Cookie the array "session" will save and restore from a db-record. In this version MySQL is used but it's should very easy to change Categories : PHP, Arrays, Cookies, MySQL, Databases | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | |
|
|
|