Convert .CSV to GD Graph
Posted: Mon Apr 07, 2008 3:54 am
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Dear Colleagues,
I'm a newbie and got problem
to write a proper code in PHP. i'm assigned to design a page to convert CSV file to GD Graph. but i stuck to store the data into mySQL(maybe got another way without store data in mySQL).
This is my coding:
The result would be:
but the objective is to create a database which the field would be based on the header of the CSV file. for this example, the header should be, 'Month', 'a', 'b', 'c', 'd', & 'e'. So how to write mySQL code for this condition? Please help me.
i've tried to write:
but i dndt seem ok.Thank You!!

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Dear Colleagues,
I'm a newbie and got problem
This is my coding:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$db = mysql_connect("localhost", "root", "") or die("Could not connect.");
if(!$db)
die("no db");
if(!mysql_select_db("cp_graph",$db))
die("No database selected.");
?>
<title>Graph</title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
ini_set("auto_detect_line_endings", 1);
$current_row = 1;
$filename = $_FILES["file"]["name"];
$handle = fopen("$filename", "r");
while ( ($data = fgetcsv($handle, 10000, ",") ) !== FALSE )
{
$number_of_fields = count($data);
if ($current_row == 1)
{
for ($c=0; $c < $number_of_fields; $c++)
{
$header_array[$c] = $data[$c];
}
}
else
{
for ($c=0; $c < $number_of_fields; $c++)
{
$data_array[$header_array[$c]] = $data[$c];
}
print_r($data_array);
}
$current_row++;
}
}
fclose($handle);
}
else
{
print "<form action='index.php' method='post' enctype='multipart/form-data'>";
print "Type file name to import:<br>";
print "<input type='file' name='file' id='file' /><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
</body>
</html>Array ( [month] => may [a] => 3800 => 5700 [c] => 1500 [d] => 800 [e] => 1200 ) Array ( [month] => june [a] => 4500 => 3456 [c] => 2300 [d] => 2570 [e] => 7650 )
but the objective is to create a database which the field would be based on the header of the CSV file. for this example, the header should be, 'Month', 'a', 'b', 'c', 'd', & 'e'. So how to write mySQL code for this condition? Please help me.
i've tried to write:
Code: Select all
$create = 'CREATE TABLE `test` ('. ' `$header_array[$c]` VARCHAR(100) NOT NULL'. ' )'. ' ENGINE = myisam;';
mysql_query($create) or die(mysql_error());~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: