<?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>PHP Magic Book - Free PHP Scripts, Tutorials and Downloads &#187; multiple columns</title>
	<atom:link href="http://www.phpmagicbook.com/tag/multiple-columns/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpmagicbook.com</link>
	<description>PHP AtoZ Reloaded, free php tutorials, free php downloads, php scripts, PHP tips</description>
	<lastBuildDate>Tue, 15 Jun 2010 13:22:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Display Records In Multiple Coulmns</title>
		<link>http://www.phpmagicbook.com/display-records-in-multiple-coulmns/</link>
		<comments>http://www.phpmagicbook.com/display-records-in-multiple-coulmns/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 12:34:06 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Useful Scripts]]></category>
		<category><![CDATA[columns]]></category>
		<category><![CDATA[multiple columns]]></category>
		<category><![CDATA[split]]></category>

		<guid isPermaLink="false">http://www.phpmagicbook.com/?p=281</guid>
		<description><![CDATA[We can display data fetched from database in a variety of ways. Depends upon our requirement. By multiple columns I mean dividing all fetches data into columns and displaying it. Here is how We can divide the resultset into multiple columns. Spliting Data into 3 Columns &#60;?php // Selecting Data From Database $sql=&#34;select * from [...]<p><a href="http://www.phpmagicbook.com/display-records-in-multiple-coulmns/">Display Records In Multiple Coulmns</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
]]></description>
			<content:encoded><![CDATA[<p>We can display data fetched from database in a variety of ways. Depends upon our requirement. By multiple columns I mean dividing all fetches data into columns and displaying it. Here is how We can divide the resultset into multiple columns.</p>
<p><span id="more-281"></span></p>
<h4>Spliting Data into 3 Columns</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Selecting Data From Database</span>
<span style="color: #000088;">$sql</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;select * from tableName order by id desc&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$check</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//total number of records set in database</span>
<span style="color: #000088;">$no</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// start loop</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$no</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Here and at the bottom where loop finishes 3 is the value which will split the fetched data into three columns</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">%</span><span style="color:#800080;">3</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Display data fetched</span>
<span style="color: #b1b100;">print</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$check</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">+</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">%</span><span style="color:#800080;">3</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>By changing value 3 which is at the beginning and end of loop, you should be able to split the fetched data in multiple columns as required. Although the above example can serve the purpose of displaying data into many columns as you want but I would like to share another example which is for 2 columns.</p>
<h4>Spliting data into Two Columns &#8211; Second Way</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//it tells the data what collumn to go to</span>
<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$column</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from tabbeName ORDER by id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//loop statement</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$myrow</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// this is the column 1</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td width='320px' class='onebrd2cover'&gt;&lt;font color='#999999'&gt;<span style="color: #006699; font-weight: bold;">$count</span>.&lt;/font&gt; &lt;a href='pageName.php?mid=<span style="color: #006699; font-weight: bold;">$myrow[catid]</span>'&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/a&gt;&lt;/td&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$myrow</span><span style="color: #009900;">&#91;</span>catname<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//this  is the column 2</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td width='320px' class='onebrd2'&gt;&lt;font color='#999999'&gt;<span style="color: #006699; font-weight: bold;">$count</span>.&lt;/font&gt; &lt;a href='pageName.php?mid=<span style="color: #006699; font-weight: bold;">$myrow[catid]</span>'&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$myrow</span><span style="color: #009900;">&#91;</span>catname<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//increment the count</span>
<span style="color: #000088;">$count</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// this is a modulus operator it gets the remainder of the equation</span>
<span style="color: #000088;">$column</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a href="http://www.phpmagicbook.com/display-records-in-multiple-coulmns/">Display Records In Multiple Coulmns</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.phpmagicbook.com/detecting-database-and-mysql-connections/" title="Detecting Database And MySQL Connections in PHP &#8211; PHP DBConnection">Detecting Database And MySQL Connections in PHP &#8211; PHP DBConnection</a></li><li><a href="http://www.phpmagicbook.com/insert-adsense-after-the-first-post-in-your-wordpress-blog/" title="Insert Adsense After the First Post in Your WordPress Blog">Insert Adsense After the First Post in Your WordPress Blog</a></li><li><a href="http://www.phpmagicbook.com/isset-function/" title="isset Function in PHP &#8211; Check for any Variable if it is Set or Not in PHP">isset Function in PHP &#8211; Check for any Variable if it is Set or Not in PHP</a></li><li><a href="http://www.phpmagicbook.com/local-and-glob-scope/" title="Local And Global Variable Scope in PHP">Local And Global Variable Scope in PHP</a></li><li><a href="http://www.phpmagicbook.com/php-photo-slide-show-with-drop-down/" title="PHP Photo Slide Show With Drop Down">PHP Photo Slide Show With Drop Down</a></li><li><a href="http://www.phpmagicbook.com/random-flash-swf-onload-php-script/" title="Random Flash SWF Onload PHP Script">Random Flash SWF Onload PHP Script</a></li><li><a href="http://www.phpmagicbook.com/local-and-remote-ip-address/" title="Local And Remote IP Address">Local And Remote IP Address</a></li><li><a href="http://www.phpmagicbook.com/add-view-delete-record/" title="Add, View, Delete Record Using PHP">Add, View, Delete Record Using PHP</a></li><li><a href="http://www.phpmagicbook.com/smarty-for-smart-developers/" title="Smarty For Smart Developers">Smarty For Smart Developers</a></li><li><a href="http://www.phpmagicbook.com/php-decrement-operator/" title="PHP Decrement Operator">PHP Decrement Operator</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.phpmagicbook.com/display-records-in-multiple-coulmns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
