\n"; } } else { $errorstr = "input failed"; if ( $_GET["q"] ) { $errorstr .= " q not an integer"; } } $canvas = @imagecreatetruecolor($width, $height) or die("Cannot Initialize new GD image stream"); include("colours.php"); if ( $image ) { imagerectangle ( $canvas, $margin , $margin , $width-$margin, $height-$margin , $white ); } if ( ! $q ) { if ( ! $image ) { print "Error!: ".$errorstr." Q is ".$_GET["q"]."
\n"; die(); } else { header('Content-Type: image/jpeg'); imagestring ( $canvas , $font , $margin , $margin , "Error!: ".$errorstr , $white ); imagejpeg($canvas); imagedestroy($canvas); die(); } } $link = mysql_pconnect ($server, $username , $password ) or $errorstr = "Could not connect: " . mysql_error(); mysql_select_db($database) or $errorstr = "Could not select database"; # ask - sellers price # bid - buyers willing to pay for. $query = "SELECT MAX(price) as maxprice , MIN(price) as minprice, MAX(volRemaining) as maxvol, MIN(volRemaining) as minvol from marketdata "; $query .= "where marketdata.typeID = ".$q." "; $query .= "and TIMESTAMPADD(DAY, marketdata.duration, marketdata.issued ) > NOW() "; if ( $debug && ! $image ) { print "SQL for min max
\n"; print $query ."
"; } $result = mysql_query($query) or $errorstr = "Query failed: " . mysql_error(); if ( mysql_num_rows ( $result ) ) { $row = mysql_fetch_array($result); $maxprice = $row['maxprice']; $minprice = $row['minprice']; $maxvol = $row['maxvol']; $minvol = $row['minvol']; } $query = "SELECT price, format(SUM(volRemaining),2) as vol, bid "; $query .= "FROM marketdata "; $query .= "where marketdata.typeID = ".$q." "; # $query .= "and bid like 'False' "; $query .= "and TIMESTAMPADD(DAY, marketdata.duration, marketdata.issued ) > NOW() "; $query .= "GROUP BY price "; $query .= "order by price"; if ( $debug && ! $image ) { print "SQL for min max
\n"; print $query ."
"; } #imagestring ( $canvas , $font , $margin , 3, $query, $white ); imagestring ( $canvas , $font , $margin , 3, "Price An Volume for Item $q", $white ); $result = mysql_query($query) or $errorstr = "Query failed: " . mysql_error(); if ( $errorstr ) { print $errorstr ; } # print $query; if ( mysql_num_rows ( $result ) < 1 ) { if ( ! $image ) { print "no market data"; die(); } else { header('Content-Type: image/jpeg'); imagestring ( $canvas , $font , $margin , $margin , "no market data".$errorstr , $white ); imagejpeg($canvas); imagedestroy($canvas); die(); } } if ( $image ) { header('Content-Type: image/jpeg'); } while($row = mysql_fetch_array($result)) { if ( preg_match ( "/(\d.*)\.?(\d.*)?e([+-])(\d.*)/" , $row['price'] ,$matches)) { $new = ( $matches[1] + $matches[2] * pow(10,- strlen($matches[2])) ) * ( pow ( 10 , $matches[3] . "1" * $matches[4] ) ) ; #$new = number_format ( $row['price'] , 2 ) ; $data[$new] = $row['vol']; } else { $data[$row['price']] = $row['vol']; } } if ( ! $image ) { print "Price Volume
"; } foreach ($data as $price => $vol) { if ( ! $image ) { # print $row['price']." ".$row['vol']." ".$row['bid']."
\n"; print $price ."(".gettype($price).") ".$vol."(".gettype($vol).")
\n"; } else { if ( $price > $minx && $row['price'] < $maxx ) { imagefilledrectangle ( $canvas, $margin, $y1 , $x2 , $y2 , $white ); imagestring ( $canvas, $font, $margin+(($row['price']/$maxx) * ($width - 2*$margin)) , $margin+($margin*$i++) , $i." ".$row['price']." ".$row['sum']." ".$row['bid'], $white ); } #imagefilledrectangle ( $image , $x1 , $y1 , $x2 , $y2 , $white ); } } # PUT THE SCALES IN HERE #$i = 0; #$minx = $minprice; #$maxx = $maxprice; #if ( $image ) { # for ($i = $minx; $i <= $maxx; $i++) { # imageline ( $canvas, $margin+(($i/$maxx) * ($width - 2*$margin)), $margin, $margin+(($i/$maxx) * ($width - 2*$margin)) , 2*$margin , $white ); # imagestring ( $canvas, $font, $margin+(($i/$maxx) * ($width - 2*$margin)), $margin, $i, $white ); # } #} else { # print "X: "; #} imagejpeg($canvas); imagedestroy($canvas); ?>