Graph script

I’m working on a page which monitors visitors to a page and places the results in a line graph.


include('../config/global.php'); // file which holds connection string

$maxHeight = $fetch($query('SELECT hits FROM propHits ORDER BY hits DESC'));
$qt=mysql_query('SELECT * FROM propHits');

header ("Content-type: image/jpg");

$x_gap=63; // The gap between each point in y axis 

$x_max=$x_gap*12; // Maximum width of the graph or horizontal axis
$y_max=$maxHeight['hits']+50; // Maximum hight of the graph or vertical axis
// Above two variables will be used to create a canvas of the image//

$im = imagecreate ($x_max, $y_max)
or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 200);
$text_color = imagecolorallocate ($im, 0, 0, 0);
$graph_color = imagecolorallocate ($im, 0, 0, 0);

// echo $nt['month'].', '.$nt['hits'];
$x2=$x1+$x_gap; // Shifting in X axis
$y2=$y_max-$nt['hits']; // Coordinate of Y axis
//Line above is to print month names on the graph
if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0
imageline ($im,$x1, $y1,$x2,$y2,$text_color); // Drawing the line between two points
$x1=$x2; // Storing the value for next draw
$first_one="no"; // Now flag is set to allow the drawing

imagejpeg ($im);


What I am looking for is to place a grid inside the graph with numbers along the side and have the monthe at the base. Does anyone know of any tutorials on how this can be done.

Also for usage i have to include the trouble with this is the end code is going to have

$qt=mysql_query('SELECT * FROM propHits WHERE id = "'.$clicked_id.'"');

With having to include the graph this way this above query will not work, is there a way around this. I have tried removing this line from the image.php and adding to the main page but it fails.

Sponsor our Newsletter | Privacy Policy | Terms of Service