<?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>BLUEice studios &#187; MySQL</title>
	<atom:link href="http://www.blueicestudios.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blueicestudios.com</link>
	<description>I make stuff for you :)</description>
	<lastBuildDate>Wed, 20 Jul 2011 09:07:32 +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>jQuery: Filter Select box with php and mysql</title>
		<link>http://www.blueicestudios.com/jquery-filter-select-box-with-php-and-mysql/</link>
		<comments>http://www.blueicestudios.com/jquery-filter-select-box-with-php-and-mysql/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 00:58:33 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[select box]]></category>

		<guid isPermaLink="false">http://www.blueicestudios.com/?p=140</guid>
		<description><![CDATA[Lets filter a select box with jQuery, Sack, PHP and MySQL&#8230;.. You may or may not need this, but it could come in handy at one point in time. So lets start.. I will show you the basics here, you may download the source at the bottom of the page. View the DEMO index.html include [...]]]></description>
			<content:encoded><![CDATA[<p>Lets filter a select box with jQuery, Sack, PHP and MySQL&#8230;..</p>
<p>You may or may not need this, but it could come in handy at one point in time. So lets start..</p>
<p>I will show you the basics here, you may download the source at the bottom of the page.</p>
<p><span id="more-140"></span></p>
<p>View the <a href="http://www.blueicestudios.com/filter_select/" target="_blank">DEMO</a></p>
<p>index.html</p>
<p>include these into the head section of the page. ajax.js is the Sack js functions. I will get into Sack later.</p>
<pre class="brush:html"><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"><!--mce:0--></script> <script src="sack.js" type="text/javascript"><!--mce:1--></script></pre>
<p>this goes into the head as well.</p>
<pre class="brush:js">var ajax = new Array();

function getTextList(sel)

{

var color = document.getElementById('color').value; //gets value from text input

document.getElementById('colorReturn').options.length = 0;

if(color.length&gt;0){

var index = ajax.length;

ajax[index] = new sack();

ajax[index].requestFile = 'getColor.php?color='+color; //sends the GET to the php page

ajax[index].onCompletion = function(){ createText(index) };

ajax[index].runAJAX();

}

}

function createText(index)

{

var obj = document.getElementById('colorReturn'); //retruns the options from the php page

eval(ajax[index].response);

}</pre>
<p>The form</p>
<pre class="brush:html">
<form method="post">
<select id="colorReturn" style="width: 200px;" name="colorReturn" size="5">
</select>
<h4>Filter the colors - Start typing black.</h4>
<input id="color" onkeyup="getTextList();" name="color" type="text" />
</form>
</pre>
<p>Thats it for the index page. pretty straight forward. So now for the fun part.</p>
<p>getColor.php &#8211; This page contains the sql and php that returns the</p>
<pre class="brush:php">mysql_connect("localhost", "username", "password") or die(mysql_error());

mysql_select_db("database") or die(mysql_error());

$color = $_GET['color'];

if(isset($_GET['color'])){

$result = mysql_query("SELECT color FROM colors WHERE color LIKE '%$color%' LIMIT 0,10")

or die(mysql_error());

while($color = mysql_fetch_array( $result ))

{

echo 'obj.options[obj.options.length] = new Option("'.$color['color'].'","'.$color['color'].'");';

}

}</pre>
<p>Its not the most detailed tutorial, but im not a tutorial guy.</p>
<p>View the <a href="http://www.blueicestudios.com/filter_select/" target="_blank">DEMO</a></p>
<p>Download the <a href="http://www.blueicestudios.com/filter_select/getColor.zip">SOURCE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blueicestudios.com/jquery-filter-select-box-with-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

