Hi All,
I am trying to design a PHP site that will take a number of sunspot groups from a database and the time they were inputted, and display them in a chart, at the moment, I have managed to get it so that it will change the location of the pixel based on number of groups, but not time, so effectively I have an X axis, but no Y axis on my graph.
The current location (at time of writing) is
http://www.tomearl.unicorn-group.co.uk/astronomy
When you submit the input form, it inputs the number of groups you specified and the current time using the now() function on the datetime field in the database.
I think I need to convert the time code to Unix time to display them using CSS pixel positioning, I use the mktime() function for that,
The code that I am using is below
index.php
PHP Code:
<html>
<head>
<title>Sunspot Viewer</title>
</head>
<body>
<h1>Tom's handy dandy sunspot viewer!</h1>
<a href="includes/input.php">Insert new record</a>
<hr width="100%" size="1">
<div>
<?php
/// Echo how many minutes have passed since script was last tested
$test = 1171566521 - time('U');
$finaltest = str_replace("-", "", $test);
echo $finaltest / 60;
/// Connect to the database
include 'includes/connect.php';
/// Start the query
$query = "SELECT * FROM sunspot_groups";
/// Execute the query
$result = mysql_query($query) or die(mysql_error());
/// Start to loop through the results
while ($row = mysql_fetch_array($result) or die(mysql_error())) {
/// Assign the array to variables, and add 100px to height to bring it up off the bottom of the page
$groups = $row[groups] + 100;
$id = $row[id];
$date = $row[date];
$adate = 1171566521 - mktime($row[date]);
$udate = str_replace("-", "", $adate);
echo "<table border=\"0\" style=\"position: absolute; bottom: $groups.0px; left: $udate.0px\"><tr><td><img src=\"includes/pixel.jpg\" height=\"2px\" width=\"2px\">$date</td></tr></table>";
}
echo "
</div>
</body>
</html>
";
?>
The connect.php
PHP Code:
<?php
$conn = mysql_connect("localhost","user","password");
mysql_select_db("database");
?>
input.php
PHP Code:
<?php
/// Check to see if the form has been posted
if (!$_POST) {
/// It hasn't
?>
<html>
<head>
<title>Input you data...</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER[PHP_SELF]; ?>">
<h1>Input your data...</h1>
<p>Number of groups:</p>
<input type="text" name="groups">
<input type="submit">
</body>
</html>
<?php
} else {
/// connect to the database
include 'connect.php';
/// Start the query
$query = "INSERT INTO sunspot_groups VALUES ('', '$_POST[groups]', now())";
// execute the query
mysql_query($query) or die(mysql_error());
echo "<h1>Done!</h1>";
}
?>
The script I used to create the database
PHP Code:
<?php
include 'connect.php';
$query1 = "CREATE TABLE sunspot_groups (
id MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
groups MEDIUMINT NOT NULL DEFAULT'0',
date DATETIME)";
mysql_query($query1) or die(mysql_error());
?>
Any help would be greatly appreciated!
Thanks
Tom