Skip to content

Instantly share code, notes, and snippets.

@AbhishekGhosh
Created August 19, 2014 08:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AbhishekGhosh/d8ec5db1afdc7278b36b to your computer and use it in GitHub Desktop.
Graph From MySQL Data
<?php
$link = mysql_connect( 'database_host', 'database_user', 'database_password' );
if ( !$link ) {
die( 'Could not connect: ' . mysql_error() );
}
$db = mysql_select_db( 'test', $link );
if ( !$db ) {
die ( 'Error selecting database \'test\' : ' . mysql_error() );
}
$query = "
SELECT *
FROM test_chart_data
ORDER BY category ASC";
$result = mysql_query( $query );
if ( !$result ) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die( $message );
}
while ( $row = mysql_fetch_assoc( $result ) ) {
echo $row['category'] . ' | ' . $row['value1'] . ' | ' .$row['value2'] . "\n";
}
mysql_close($link);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment