<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technical Side of E-Business Juncture &#187; histogram</title>
	<atom:link href="http://tech.ebusinessjuncture.com/tag/histogram/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.ebusinessjuncture.com</link>
	<description>Tech Tips</description>
	<lastBuildDate>Mon, 22 Feb 2010 22:47:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP: script using php and gd to generate or create a histogram</title>
		<link>http://tech.ebusinessjuncture.com/2009/12/php-script-using-php-and-gd-to-generate-or-create-a-histogram/</link>
		<comments>http://tech.ebusinessjuncture.com/2009/12/php-script-using-php-and-gd-to-generate-or-create-a-histogram/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 02:02:47 +0000</pubDate>
		<dc:creator>Mike Kniaziewicz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[histogram]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[powerball]]></category>

		<guid isPermaLink="false">http://tech.ebusinessjuncture.com/?p=289</guid>
		<description><![CDATA[Here is a simple script to create a histogram using mysql, php and gd. The key point to remember here is to create a &#8220;SELECT&#8221; only account for extracting the records. Do not provide any more privileges than you have to provide. Please comment if you have a different way to perform the same task.
Here [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple script to create a histogram using mysql, php and gd. The key point to remember here is to create a &#8220;SELECT&#8221; only account for extracting the records. Do not provide any more privileges than you have to provide. Please comment if you have a different way to perform the same task.</p>
<p>Here is the final image followed by the code:<br />
<img src="http://ebjnow.com/images/pbimage_histogram.png" alt="Histogram" /></p>
<p><strong>Here are the contents of the pbimages_histogram.php file</strong></p>
<pre>#Let us get our database from a mysql database
#First we need to connect to the database or die trying
# I would create an account with read-only or select only access
$lottery_con = mysql_connect('localhost','select_lottery','1234try');
if (!$lottery_con){
	 die ('Could not connect to lottery');
   }
mysql_select_db("lottery") or die (mysql_error());

#Let us create our first query
$wb1_match_pb = mysql_query("SELECT count(wb1) FROM lottery
 where wb1 = pb");
$wb2_match_pb = mysql_query("SELECT count(wb2) FROM lottery
 where wb2 = pb");
$wb3_match_pb = mysql_query("SELECT count(wb3) FROM lottery
 where wb3 = pb");
$wb4_match_pb = mysql_query("SELECT count(wb4) FROM lottery
 where wb4 = pb");
$wb5_match_pb = mysql_query("SELECT count(wb5) FROM lottery
 where wb5 = pb");
$tot_record = mysql_query("SELECT count(pb) FROM lottery");
#As soon as you connect make sure you create the close
 connection
$cntwb1 = mysql_fetch_array($wb1_match_pb);
$cntwb2 = mysql_fetch_array($wb2_match_pb);
$cntwb3 = mysql_fetch_array($wb3_match_pb);
$cntwb4 = mysql_fetch_array($wb4_match_pb);
$cntwb5 = mysql_fetch_array($wb5_match_pb);
$cntwbT = $cntwb1[0] + $cntwb2[0] + $cntwb3[0] + $cntwb4[0]
 + $cntwb5[0];
$cnttr = mysql_fetch_array($tot_record);
mysql_close($lottery_con);
#Let us create the histogram
$pb_histogram_image = imagecreate(250,215)
      or die('Cannot Initialize new GD image stream');
$pb_text = imagecolorallocate($pb_histogram_image,0,0,0);
$blue = imagecolorallocate($pb_histogram_image, 0, 0, 255);
$black = imagecolorallocate($pb_histogram_image,0,0,0);
$red = imagecolorallocate($pb_histogram_image, 255, 0, 0);
$green = imagecolorallocate($pb_histogram_image,0,255,0);
$gray = imagecolorallocate($pb_histogram_image,150,150,150);
$orange = imagecolorallocate($pb_histogram_image,255,127,0);
$coral = imagecolorallocate($pb_histogram_image,240,128,128);
$white = imagecolorallocate($pb_histogram_image, 255, 255, 255);
imagefilltoborder($pb_histogram_image,0,0,$black,$white);
imageline($pb_histogram_image,0,0,0,250,$black);
imageline($pb_histogram_image,0,0,250,0,$black);
imageline($pb_histogram_image,249,0,249,213,$black);
imageline($pb_histogram_image,0,214,250,214,$black);
#Let us add the counts
imagestring($pb_histogram_image,2,15,200,"wb1",$black);
imagestring($pb_histogram_image,2,60,200,"wb2",$black);
imagestring($pb_histogram_image,2,95,200 ,"wb3",$black);
imagestring($pb_histogram_image,2,140,200,"wb4",$black);
imagestring($pb_histogram_image,2,180,200 ,"wb5",$black);
imagestring($pb_histogram_image,2,213,200,"wb Tot",$black);
imagestring($pb_histogram_image,3,10,20,"    Histogram of
 white balls",$black);
imagestring($pb_histogram_image,3,10,35,"       matching
powerball",$black);
imagestring($pb_histogram_image,3,10,50,"         Records:
 " . $cnttr[0],$black);
imagestring($pb_histogram_image,2,15,200 - $cntwb1[0] - 20,
$cntwb1[0],$black);
imagestring($pb_histogram_image,2,60,200 - $cntwb2[0] - 20,
$cntwb2[0],$black);
imagestring($pb_histogram_image,2,95,200 - $cntwb3[0] - 20,
$cntwb3[0],$black);
imagestring($pb_histogram_image,2,140,200 - $cntwb4[0] - 20,
$cntwb4[0],$black);
imagestring($pb_histogram_image,2,180,200 - $cntwb5[0] - 20,
$cntwb5[0],$black);
imagestring($pb_histogram_image,2,220,200 - $cntwbT - 20,
$cntwbT,$black);
#Let us make the bars
imagefilledrectangle($pb_histogram_image,5,200,40,200 -
$cntwb1[0],$blue);
imagefilledrectangle($pb_histogram_image,45,200,80,200 -
$cntwb2[0],$red);
imagefilledrectangle($pb_histogram_image,85,200,120,200 -
$cntwb3[0],$green);
imagefilledrectangle($pb_histogram_image,125,200,155,200 -
$cntwb4[0],$gray);
imagefilledrectangle($pb_histogram_image,165,200,205,200 -
$cntwb5[0],$orange);
imagefilledrectangle($pb_histogram_image,210,200,245,200 -
$cntwbT,$coral);

header ('Content-type: image/png');
imagepng($pb_histogram_image);
imagedestroy($pb_histogram_image);
</pre>
<p>Let me know what you think and as always please check out the offerings of my sponsors.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.ebusinessjuncture.com/2009/12/php-script-using-php-and-gd-to-generate-or-create-a-histogram/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
