WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Finds the median in an array of numbers - Can be used with a MySql database column read into an array
Categories : PHP, Arrays, Databases, MySQL Click here to Update Your Picture
Bill Simon
Date : May 22nd 2002
Grade : 4 of 5 (graded 1 times)
Viewed : 7704
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Bill Simon
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

// 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



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
How to load a query result into a PHP Array
Categories : PHP, Databases, Arrays, MySQL
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
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
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
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
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
Function for retrieving MySQL enum values into a PHP array.
Categories : PHP, Databases, MySQL, Arrays
AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page.
Categories : PHP, AJAX, Databases, MySQL, Java Script
Identify and log search engine access (spiders, robots, etc.) to a page.
Categories : HTTP, Environment Variables, PHP, MySQL, Databases
Visits-tracking
Categories : PHP, Databases, MySQL, Errors and Logging, Functions
A simple script to count and report hits and the last modification time of an HTML page. Requires MySQL support (other DBs should work too, except possibly mSQL).
Categories : HTTP, MySQL, PHP, Databases
php-gtk mysql querying tool
Categories : PHP-GTK, MySQL, PHP, Databases