Skip to content

Instantly share code, notes, and snippets.

@paddya
Created October 30, 2012 17:14
Show Gist options
  • Save paddya/3981622 to your computer and use it in GitHub Desktop.
Save paddya/3981622 to your computer and use it in GitHub Desktop.
<?php
// database access
$dbName = '';
$dbUser = '';
$dbPass = '';
$dbHost = 'localhost';
// table
$table = 'values';
// columns to ignore
$ignore = array();
mysql_connect($dbHost, $dbUser, $dbPass) OR die(mysql_error());
mysql_select_db($dbName) OR die(mysql_error());
$inst = mysql_query("SELECT * FROM " . $table) OR die(mysql_error());
$values = array();
while($row = mysql_fetch_assoc($inst)) {
foreach($row AS $col => $content) {
if(in_array($col, $ignore)) {
continue;
}
if(!isset($values[$col])) {
$values[$col] = array();
}
$values[$col][] = $content;
}
}
// $values[$columnName] contains all values in that column
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment