<?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>Kevin Dubois &#187; html</title>
	<atom:link href="http://kevindubois.com/blog/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://kevindubois.com/blog</link>
	<description>A LAMP consultant in the greater Salt Lake City Area</description>
	<lastBuildDate>Mon, 24 Oct 2011 16:32:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Group TD (table data) without using rowspan when left joining in mySQL</title>
		<link>http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/</link>
		<comments>http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 15:43:59 +0000</pubDate>
		<dc:creator>Kevin Dubois</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[left join]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[td]]></category>
		<category><![CDATA[tr]]></category>

		<guid isPermaLink="false">http://kevindubois.com/blog/?p=6</guid>
		<description><![CDATA[Tweet When outputting data from a database using left joins you often get redundant data in your output.  Say you have a table with vendor information, and a second table containing the customers for each vendor.  If you want to &#8230; <a href="http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="border:1px solid #808080;background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fkevindubois.com%2Fblog%2F2008%2F10%2F30%2Fgroup-td-table-data-without-using-rowspan-when-left-joining-in-mysql%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" style="border:none; overflow:hidden; width=85px; height:21px;"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/"  data-text="Group TD (table data) without using rowspan when left joining in mySQL" data-count="horizontal">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>When outputting data from a database using left joins you often get redundant data in your output.  Say you have a table with vendor information, and a second table containing the customers for each vendor.  If you want to display a table with the vendor names and their customers, you&#039;ll most likely want to use a left join.</p>
<p>The problem is, when you output your data you&#039;ll repeat the vendor name for each customer they have.  It makes the table look cluttered and hard to read.  Not to worry though, there is an easy solution!</p>
<p>All you have to do is create 2 classes:</p>
<blockquote><p><span style="color: #800080;">.noblanktd{color:inherit; border-top:1px solid #000; border-top:1px solid #000}<br />
.blanktd{color:white; }</span></p></blockquote>
<p>and here&#039;s the php code:</p>
<blockquote><p><span style="color: #800080;">function outputmystuff(){<br />
// get your data here eg<br />
$query = &#034;SELECT v.id, v.name as vendorname, c.name as customername FROM vendors as v LEFT JOIN customers as c ON v.id = c.vendor_id&#034;;<br />
$result = mysql_query($query);<br />
</span></p>
<p><span style="color: #800080;">$oldID = false;<br />
while($row = mysql_fetch_assoc($result)){<br />
$ID = $row['id'];<br />
if($oldID == $ID){<br />
$class = &#039;blanktd&#039;;<br />
} else{<br />
$class = &#034;noblanktd&#034;;<br />
}<br />
$returnval .= &lt;&lt;&lt;EOD<br />
&lt;tr&gt;<br />
&lt;td class=&#034;{$class}&#034;&gt;{$row['vendorname']}&lt;/td&gt;<br />
&lt;td class=&#034;noblanktd&#034;&gt;{$row['customername']}&lt;/td&gt;<br />
&lt;/tr&gt;<br />
EOD;<br />
$oldID = $ID;</span></p>
<p><span style="color: #800080;">}</span></p>
<p><span style="color: #800080;">return $returnval;</span></p>
<p><span style="color: #800080;">}</span></p></blockquote>
<p>and last but not least the html</p>
<blockquote><p><span style="color: #800080;">&lt;table class=&#034;repTable&#034;&gt;<br />
&lt;tr&gt;<br />
&lt;th&gt;Vendor Name&lt;/th&gt;<br />
&lt;th&gt;Customer Name&lt;/th&gt;<br />
&lt;/tr&gt;<br />
&lt;?=outputmystuff()?&gt;<br />
&lt;/table&gt;</span></p></blockquote>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="kevin.dubois@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy Me a Beer for Group TD (table data) without using rowspan when left joining in mySQL" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="1" /><input type="image" src="http://kevindubois.com/blog/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="" title="" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=kevin.dubois@gmail.com&amp;currency_code=USD&amp;amount=1&amp;return=&amp;item_name=Buy+Me+a+Beer+for+Group+TD+(table+data)+without+using+rowspan+when+left+joining+in+mySQL" target="paypal">Was this post helpful? Buy me a drink :-)</a></p>]]></content:encoded>
			<wfw:commentRss>http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding additional text fields with Javascript</title>
		<link>http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/</link>
		<comments>http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 16:11:46 +0000</pubDate>
		<dc:creator>Kevin Dubois</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://kevindubois.com/blog/?p=3</guid>
		<description><![CDATA[Tweet ** UPDATE: This functionality is outdated. Look at a more recent post on how to add more field to a form field: &#039;Add More&#039; form fields with javascript / jquery ** One of my clients needed the ability for &#8230; <a href="http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="border:1px solid #808080;background-color:#F0F4F9;">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fkevindubois.com%2Fblog%2F2008%2F10%2F16%2Fadding-additional-text-fields-with-javascript%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" style="border:none; overflow:hidden; width=85px; height:21px;"></iframe></div>
			<div style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/"></g:plusone>
			</div>
			<div style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/"  data-text="Adding additional text fields with Javascript" data-count="horizontal">Tweet</a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>** UPDATE: This functionality is outdated.  Look at a more recent post on how to add more field to a form field:<br />
<a href="http://kevindubois.com/blog/2011/10/24/add-more-form-fields-with-javascript-jquery/">&#039;Add More&#039; form fields with javascript / jquery</a> **</p>
<p>One of my clients needed the ability for users to refer their family and friends to the website by sending them an email.   The idea was to have 5 fixed fields, and the ability to add more fields on the fly before hitting submit.</p>
<p><strong>Step 1</strong> is obviously adding the static html code (with a tiny bit of php to avoid redundancy):</p>
<blockquote><p>&lt;form action=&#034;mysubmitpage.php&#034; method=&#034;post&#034;&gt;<br />
&lt;div id=&#039;fields&#039;&gt;<br />
&lt;? for($i=1; $i&lt;6; $i++){?&gt;<br />
&lt;div&gt;<br />
name: &lt;input type=&#034;text&#034; name=&#034;refname&lt;?=$i?&gt;&#034; /&gt;</p>
<p>email: &lt;input type=&#034;text&#034; name=&#034;refemail&lt;?=$i?&gt;&#034;  /&gt;</p>
<p>&lt;/div&gt;<br />
&lt;? }?&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;div style=&#034;margin-top:5px;&#034;&gt;<br />
&lt;input type=&#034;submit&#034; value=&#034;Send Invitations&#034; name=&#034;send&#034; /&gt;<br />
&lt;/div&gt;</p>
<p>&lt;/form&gt;</p></blockquote>
<p><strong>Step 2</strong> involves adding an &#039;add more&#039; link, which calls the javascript function that adds the field.  I&#039;m passing the number of the next field into the function, so when the time comes to submit it to the server I can distinguish the fields.  I would have preferred to use IE&#039;s outerHTML but that&#039;s not supported in my preferred browser firefox, so to keep everything neat I get the existing fields and append the new field to the end of the string.   I also replace the &#034;add more&#034; link so next time it is clicked the number 7, 8, 9 etc is passed.</p>
<blockquote><p>&lt;script language=&#034;javascript&#034;&gt;<br />
function addrefField(i){<br />
var newfieldContent = &#034;&lt;div&gt;name: &lt;input type=\&#034;text\&#034; name=\&#034;refname&#034;+i+&#034;\&#034; /&gt; email: &lt;input type=\&#034;text\&#034; name=\&#034;refemail&#034;+i+&#034;\&#034; /&gt; &lt;/div&gt; \n&#034;;</p>
<p>var oldfieldContent = document.getElementById(&#039;fields&#039;).innerHTML;</p>
<p>el = document.getElementById(&#039;fields&#039;);<br />
el.innerHTML = oldfieldContent + newfieldContent;</p>
<p>x = i + 1;<br />
var addmoreContent = document.getElementById(&#039;addmorelink&#039;);<br />
addmoreContent.innerHTML = &#039;&lt;div&gt;&lt;a href=&#034;javascript:addrefField(&#039;+x+&#039;)&#034;&gt;add more&lt;/a&gt;&lt;/div&gt;&lt;input type=&#034;hidden&#034; name=&#034;numberfields&#034; value=&#034;&#039;+i+&#039;&#034; /&gt;&#039;;</p>
<p>}</p>
<p>&lt;/script&gt;</p>
<p>&lt;div id=&#039;addmorelink&#039;&gt;<br />
&lt;a href=&#034;javascript:addrefField(6)&#034;&gt;add more&lt;/a&gt;<br />
&lt;input type=&#034;hidden&#034; name=&#034;numberfields&#034; value=&#034;6&#034; /&gt;<br />
&lt;/div&gt;</p></blockquote>
<p><strong>Step 3 </strong>: The above code seems to work fine in IE, but in Firefox there is a problem: the value of the existing fields is reset to whatever the DOM originally served up to the user.  So if the user had started to fill out the fields and then clicked the &#039;add more&#039; link, all fields would have been emptied.  With every problem comes a solution ofcourse.  I googled my problem and stumbled upon <a title="this post" href="http://dev-answers.blogspot.com/2007/08/firefox-does-not-reflect-input-form.html" target="_blank">this post</a>.  By adding a function (updateDOM()) on the onBlur event for each field, we can update the DOM to reflect the already inserted values.  So here&#039;s the entire code for the form:</p>
<blockquote><p>&lt;script language=&#034;javascript&#034;&gt;<br />
function addrefField(i){<br />
var newfieldContent = &#034;&lt;div&gt;name: &lt;input type=\&#034;text\&#034; name=\&#034;refname&#034;+i+&#034;\&#034; onBlur=\&#034;updateDOM(this)\&#034; /&gt; email: &lt;input type=\&#034;text\&#034; name=\&#034;refemail&#034;+i+&#034;\&#034; onBlur=\&#034;updateDOM(this)\&#034; /&gt; &lt;/div&gt; \n&#034;;</p>
<p>var oldfieldContent = document.getElementById(&#039;fields&#039;).innerHTML;</p>
<p>el = document.getElementById(&#039;fields&#039;);<br />
el.innerHTML = oldfieldContent + newfieldContent;</p>
<p>x = i + 1;<br />
var addmoreContent = document.getElementById(&#039;addmorelink&#039;);<br />
addmoreContent.innerHTML = &#039;&lt;div&gt;&lt;a href=&#034;javascript:addrefField(&#039;+x+&#039;)&#034;&gt;add more&lt;/a&gt;&lt;/div&gt;&lt;input type=&#034;hidden&#034; name=&#034;numberfields&#034; value=&#034;&#039;+i+&#039;&#034; /&gt;&#039;;</p>
<p>}</p>
<p>function updateDOM(inputField) {<br />
// if the inputField ID string has been passed in, get the inputField object<br />
if (typeof inputField == &#034;string&#034;) {<br />
inputField = document.getElementById(inputField);<br />
}</p>
<p>if (inputField.type == &#034;select-one&#034;) {<br />
for (var i=0; i&lt;inputField.options.length; i++) {<br />
if (i == inputField.selectedIndex) {<br />
inputField.options[inputField.selectedIndex].setAttribute(&#034;selected&#034;,&#034;selected&#034;);<br />
}<br />
}<br />
} else if (inputField.type == &#034;text&#034;) {<br />
inputField.setAttribute(&#034;value&#034;,inputField.value);<br />
} else if (inputField.type == &#034;textarea&#034;) {<br />
inputField.setAttribute(&#034;value&#034;,inputField.value);<br />
} else if ((inputField.type == &#034;checkbox&#034;) || (inputField.type == &#034;radio&#034;)) {<br />
if (inputField.checked) {<br />
inputField.setAttribute(&#034;checked&#034;,&#034;checked&#034;);<br />
} else {<br />
inputField.removeAttribute(&#034;checked&#034;);<br />
}<br />
}<br />
}</p>
<p>&lt;/script&gt;</p>
<p>&lt;form action=&#034;index.php&#034; method=&#034;post&#034;&gt;<br />
&lt;div id=&#039;fields&#039;&gt;<br />
&lt;? for($i=1; $i&lt;6; $i++){?&gt;<br />
&lt;div&gt;<br />
name: &lt;input type=&#034;text&#034; name=&#034;refname&lt;?=$i?&gt;&#034; onBlur=&#034;updateDOM(this)&#034; /&gt; email:<br />
&lt;input type=&#034;text&#034; name=&#034;refemail&lt;?=$i?&gt;&#034; onBlur=&#034;updateDOM(this)&#034; /&gt; &lt;/div&gt;<br />
&lt;? }?&gt;</p>
<p>&lt;/div&gt;<br />
&lt;div id=&#039;addmorelink&#039;&gt;<br />
&lt;a href=&#034;javascript:addrefField(6)&#034;&gt;add more&lt;/a&gt;<br />
&lt;input type=&#034;hidden&#034; name=&#034;numberfields&#034; value=&#034;6&#034; /&gt;<br />
&lt;/div&gt;<br />
&lt;div style=&#034;margin-top:5px;&#034;&gt;   &lt;input type=&#034;submit&#034; value=&#034;Send Invitations&#034; name=&#034;send&#034; /&gt; &lt;/div&gt;</p>
<p>&lt;/form&gt;</p></blockquote>
<p><strong>Step 4</strong> : All that&#039;s left is processing the fields on the next page:</p>
<blockquote><p>&lt;?php</p>
<p>$loops = $_POST['numberfields'];<br />
for($i=1;$i&lt;=$loops;$i++){</p>
<p>$namepost = &#034;refname&#034; . $i;<br />
$name = $_POST[$namepost];<br />
$emailpost = &#034;refemail&#034; . $i;<br />
$email = $_POST[$emailpost];<br />
if($name &amp;&amp; $email){<br />
echo $name .&#039; &#039; .$email;<br />
echo &#039;&lt;br /&gt;&#039;;<br />
}</p>
<p>}</p>
<p>?&gt;</p></blockquote>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="kevin.dubois@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy Me a Beer for Adding additional text fields with Javascript" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="1" /><input type="image" src="http://kevindubois.com/blog/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="" title="" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=kevin.dubois@gmail.com&amp;currency_code=USD&amp;amount=1&amp;return=&amp;item_name=Buy+Me+a+Beer+for+Adding+additional+text+fields+with+Javascript" target="paypal">Was this post helpful? Buy me a drink :-)</a></p>]]></content:encoded>
			<wfw:commentRss>http://kevindubois.com/blog/2008/10/16/adding-additional-text-fields-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

