<?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>iBlog random &#187; array</title>
	<atom:link href="http://blog.zurka.us/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zurka.us</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 28 May 2013 20:28:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6</generator>
		<item>
		<title>Create an array for a tag cloud in PHP</title>
		<link>http://blog.zurka.us/create-array-tag-cloud-php/</link>
		<comments>http://blog.zurka.us/create-array-tag-cloud-php/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 18:22:35 +0000</pubDate>
		<dc:creator>nasal</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tag]]></category>

		<guid isPermaLink="false">http://blog.zurka.us/?p=579</guid>
		<description><![CDATA[Everyone tells us how to create a tag cloud with an array.. but how to actually create the array with the data that we fetch from our database? This is how I do it. The table we are working in is &#8220;pictures&#8221; and the field with the tags is &#8220;tags&#8220;. The tags are separated with [&#8230;]]]></description>
				<content:encoded><![CDATA[<div style="padding-top:15px;padding-right:0px;padding-bottom:0px;padding-left:0px;;" class="linksalpha_widget">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=iBlog+random&link=http%3A%2F%2Fblog.zurka.us%2Fcreate-array-tag-cloud-php%2F&title=Create+an+array+for+a+tag+cloud+in+PHP&desc=Everyone+tells+us+how+to+create+a+tag+cloud+with+an+array..+but+how+to+actually+create+the+array+with+the+data+that+we+fetch+from+our+database%3F+This+is+how+I+do+it.+The+table+we+are+working+in+is+%26quot%3Bpictures%26quot%3B+and+the+field+with+the+tags+is+%26quot%3Btags%26quot%3B.+The+tags+are+separated+with+a+space+%28for+example%3A&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=&twrelated1=&twrelated2=&twctr=1&lnkdshow=noshow&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=1&diggbutton=1&diggctr=1&stblbutton=1&stblctr=1&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div><p>Everyone tells us how to create a tag cloud with an array.. but how to actually create the array with the data that we fetch from our database?</p>
<p>This is how I do it. The table we are working in is &#8220;<strong>pictures</strong>&#8221; and the field with the tags is &#8220;<strong>tags</strong>&#8220;. The tags are separated with a <strong>space</strong> (for example: sunset beautiful evening).</p>
<pre class="brush: php">
$query = mysql_query(&#039;select * from pictures where tags != &quot;&quot; group by tags&#039;);

while ($fetch = mysql_fetch_assoc($query)) {
	$ex = explode(&quot; &quot;, $fetch[&#039;tags&#039;]);
	$c = count($ex);
	for ($i = 0; $i &lt; $c; $i++) {
		$tags[] .= $ex[$i];
	}
}
</pre>
<p><span id="more-579"></span></p>
<p>What I do is fetch the data from all the fields named &#8220;tags&#8221; that are not empty. Then I separate the tags with the explode() function and I get an array. I count this array and I add every member of this array to my <strong>$tags</strong> array, which is the array that will include all the tags and which I&#8217;m going to use.</p>
<p>Then the usual code comes into play:</p>
<pre class="brush: php">
$c = array_count_values($tags); //count the array

$max_size = 32; //max size of the font in pixels
$min_size = 11; //min size of the font

$max_qty = max(array_values($c));
$min_qty = min(array_values($c));

$spread = $max_qty - $min_qty;
if ($spread == 0) {
	$spread = 1;
}

$step = ($max_size - $min_size) / ($spread);

foreach ($c as $key =&gt; $value) {
	$size = round($min_size + (($value - $min_qty) * $step)) . &#039;px&#039;;
	$title = $value . &#039; pictures with the tag &#039; . $key;
echo &#039;&lt;span style=&quot;font-size: &#039; . $size . &#039;&quot; title=&quot;&#039; . $title . &#039;&quot;&gt;&#039; . $key . &#039;&lt;/span&gt; &#039;;
}
</pre>
<p>This is it, all you need is a field in the table with the name <strong>tags</strong> and then you save your tags there, separated with a blank space.</p>
<p>If you have any questions feel free to ask, if you think I don&#8217;t know how to write in english please tell me and I will try harder <img src='http://blog.zurka.us/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  If you think this code sucks and have a better one please post it in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zurka.us/create-array-tag-cloud-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
