<?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; howto</title>
	<atom:link href="http://blog.zurka.us/tag/howto/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>MySQL variant for PHP&#8217;s in_array</title>
		<link>http://blog.zurka.us/mysql-variant-for-phps-in_array/</link>
		<comments>http://blog.zurka.us/mysql-variant-for-phps-in_array/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 13:54:56 +0000</pubDate>
		<dc:creator>nasal</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.zurka.us/?p=1021</guid>
		<description><![CDATA[So you have an array, let&#8217;s call it $array. $array = array(&#039;one&#039;, &#039;two&#039;, &#039;three&#039;); And you want to do a MySQL query that will check if one of the values in the array are present or similar or whatever. In PHP it would look like this: if (in_array(&#039;one&#039;, $array)) and it would return true. Now [&#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%2Fmysql-variant-for-phps-in_array%2F&title=MySQL+variant+for+PHP%27s+in_array&desc=So+you+have+an+array%2C+let%27s+call+it+%24array.+%24array+%3D+array%28%27one%27%2C+%27two%27%2C+%27three%27%29%3B+And+you+want+to+do+a+MySQL+query+that+will+check+if+one+of+the+values+in+the+array+are+present+or+similar+or+whatever.+In+PHP+it+would+look+like+this%3A+if+%28in_array%28%27one%27%2C+%24array%29%29+and+it+would+return+true.+Now+to+do&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>So you have an array, let&#8217;s call it $array.</p>
<pre class="brush: php">$array = array(&#039;one&#039;, &#039;two&#039;, &#039;three&#039;);</pre>
<p>And you want to do a MySQL query that will check if one of the values in the array are present or similar or whatever. In PHP it would look like this:</p>
<pre class="brush: php">if (in_array(&#039;one&#039;, $array))</pre>
<p>and it would return true. Now to do this in MySQL we can use (along other things but I use this one) the <strong>IN</strong> statement.</p>
<pre class="brush: php">
mysql_query(&#039;select something from table where one IN (&quot;&#039; . implode(&#039;&quot;,&quot;&#039;, $array) . &#039;&quot;)&#039;);
</pre>
<p>Why is this useful? Let&#8217;s say you&#8217;ve got an array of file extensions (pictures) and you have a database with some files in it, pictures, music, videos. You want to display only the pictures, because you want to display the last 15 uploaded pictures. Let&#8217;s say you have the filename and extension (filename = hack.jpg) stored in your database. Let&#8217;s see an example of what you could do&#8230;</p>
<pre class="brush: php">
mysql_query(&#039;select id, name, filename from uploads where substr(filename, -3) IN (&quot;&#039; . implode(&#039;&quot;,&quot;&#039;, $pics) . &#039;&quot;) order by id desc limit 12&#039;);
</pre>
<p>And that&#8217;s it. Easy peasy!</p>
<p>Have swing!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zurka.us/mysql-variant-for-phps-in_array/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
