<?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>David Tavarez's Home at davidtavarez.com &#187; html</title>
	<atom:link href="http://www.davidtavarez.com/archives/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidtavarez.com</link>
	<description>Just another weblog...</description>
	<lastBuildDate>Sat, 31 Jul 2010 16:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Code snippets in php to generate elements forms</title>
		<link>http://www.davidtavarez.com/archives/code-snippets-in-php-to-generate-elements-forms/</link>
		<comments>http://www.davidtavarez.com/archives/code-snippets-in-php-to-generate-elements-forms/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 04:11:30 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=225</guid>
		<description><![CDATA[This is a compilation of some functions to generate elements like checkboxes, radiogroups, inputs and more. Allmost all these functions receive an associative array as main parameter to generate the html code. You could use these functions to generate: Checkboxes RadioGroups Inputs Select lists Text Areas Examples Extra function for these examples: &#160; /** * [...]]]></description>
			<content:encoded><![CDATA[<p>This is a compilation of some functions to generate elements like checkboxes, radiogroups, inputs and more. Allmost all these functions receive an associative array as main parameter to generate the html code.</p>
<p>You could use these functions to generate:</p>
<ul>
<li>Checkboxes</li>
<li>RadioGroups</li>
<li>Inputs</li>
<li>Select lists</li>
<li>Text Areas</li>
</ul>
<p><strong>Examples</strong><br />
<span id="more-225"></span><br />
Extra function for these examples:</p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * ejecutarConsulta()
 *
 * @param string $sql
 * @param resource $link
 * @param bool $obtenerArreglo
 * @return
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ejecutarConsulta<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span>, <span style="color: #0000ff;">$link</span>, <span style="color: #0000ff;">$obtenerArreglo</span> = <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/is_string" onclick="urchinTracker('/outgoing/www.php.net/is_string?referer=');"><span style="color: #000066;">is_string</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
    <span style="color: #0000ff;">$result</span> = <a href="http://www.php.net/mysql_query" onclick="urchinTracker('/outgoing/www.php.net/mysql_query?referer=');"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span>, <span style="color: #0000ff;">$link</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#41;</span>
        <a href="http://www.php.net/exit" onclick="urchinTracker('/outgoing/www.php.net/exit?referer=');"><span style="color: #000066;">exit</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Error: '</span> . <a href="http://www.php.net/mysql_error" onclick="urchinTracker('/outgoing/www.php.net/mysql_error?referer=');"><span style="color: #000066;">mysql_error</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">else</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$obtenerArreglo</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0000ff;">$arrTemp</span> = <a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_num_rows" onclick="urchinTracker('/outgoing/www.php.net/mysql_num_rows?referer=');"><span style="color: #000066;">mysql_num_rows</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span> = <a href="http://www.php.net/mysql_fetch_assoc" onclick="urchinTracker('/outgoing/www.php.net/mysql_fetch_assoc?referer=');"><span style="color: #000066;">mysql_fetch_assoc</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                    <span style="color: #0000ff;">$arrTemp</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$row</span>;
            <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span>
                <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$arrTemp</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;</pre>
<p>code</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">&quot;SELECT * FROM modelo WHERE marca_id = 1&quot;</span>;
<span style="color: #0000ff;">$select</span> = getSelect<span style="color: #66cc66;">&#40;</span>ejecutarConsulta<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span>,<span style="color: #0000ff;">$link</span><span style="color: #66cc66;">&#41;</span>,
<span style="color: #ff0000;">&quot;modelo_id&quot;</span>,<span style="color: #ff0000;">&quot;id&quot;</span>,<span style="color: #ff0000;">&quot;nombre&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>output</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/select.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/select.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;select</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;marca_id&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;marca_id&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/option.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/option.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;-1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Seleccione una Opción<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/option.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/option.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;36&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Abarth<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/option.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/option.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Acura<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/option.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/option.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;option</span></a> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;37&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Alfa Romeo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select&gt;</span></span>
&nbsp;</pre>
<p>code</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$AllAccesorios</span> = <span style="color: #ff0000;">&quot;SELECT * FROM  `accesorio`
ORDER BY `accesorio`.`descripcion` ASC&quot;</span>;
<a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color: #000066;">echo</span></a> getCheckbox<span style="color: #66cc66;">&#40;</span>ejecutarConsulta<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$AllAccesorios</span>,<span style="color: #0000ff;">$link</span><span style="color: #66cc66;">&#41;</span>,
<span style="color: #ff0000;">&quot;accesorios&quot;</span>, <span style="color: #ff0000;">&quot;id&quot;</span>, <span style="color: #ff0000;">&quot;descripcion&quot;</span>, <span style="color: #ff0000;">&quot;accesorioschkbx&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>output</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/div.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;accesorioschkbx&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/input.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/input.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;input</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;accesorios[]&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;accesorios&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;8&quot;</span>
<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;checkbox&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Alarma<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/div.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;accesorioschkbx&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/input.html" onclick="urchinTracker('/outgoing/december.com/html/4/element/input.html?referer=');"><span style="color: #000000; font-weight: bold;">&lt;input</span></a> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;accesorios[]&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;accesorios&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;9&quot;</span>
<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;checkbox&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Aros Magnesio<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;</pre>
<p><strong>The Code</strong></p>
<p>To download all the function this is te link: <a href='http://www.davidtavarez.com/wp-content/2008/12/generatingelements.zip'>generatingelements.zip</a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/code-snippets-in-php-to-generate-elements-forms/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/code-snippets-in-php-to-generate-elements-forms/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/code-snippets-in-php-to-generate-elements-forms/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/code-snippets-in-php-to-generate-elements-forms/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/code-snippets-in-php-to-generate-elements-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
