<?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>Bright Cherry</title>
	<atom:link href="http://www.brightcherry.co.uk/scribbles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brightcherry.co.uk/scribbles</link>
	<description></description>
	<lastBuildDate>Mon, 08 Mar 2010 23:01:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Ajax JQuery / PHP &#8211; Refresh Table When Inserting Row Into a MySQL Database</title>
		<link>http://www.brightcherry.co.uk/scribbles/2010/03/09/ajax-jquery-php-refresh-table-when-inserting-row-into-a-mysql-database/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2010/03/09/ajax-jquery-php-refresh-table-when-inserting-row-into-a-mysql-database/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 23:01:15 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=209</guid>
		<description><![CDATA[I&#8217;ve had a few people asking me how to refresh a table (not the entire page) when inserting rows into a MySQL database, so I thought I&#8217;d quickly put together a small demo.
Here&#8217;s a basic demo of what I&#8217;m talking about. If you populate the form and press &#8220;Submit&#8221; you&#8217;ll notice the table updates without [...]


Related posts:<ol><li><a href='http://www.brightcherry.co.uk/scribbles/2008/12/11/ajax-jquery-contact-form-with-validation/' rel='bookmark' title='Permanent Link: Ajax Jquery Contact Form With Validation'>Ajax Jquery Contact Form With Validation</a></li><li><a href='http://www.brightcherry.co.uk/scribbles/2009/02/26/jquery-auto-refresh-div-every-x-seconds/' rel='bookmark' title='Permanent Link: JQuery- Auto Refresh Div Every X Seconds'>JQuery- Auto Refresh Div Every X Seconds</a></li><li><a href='http://www.brightcherry.co.uk/scribbles/2008/11/14/mysql-php-show-tables-in-database/' rel='bookmark' title='Permanent Link: MySQL &#038; PHP- Show Tables In Database'>MySQL &#038; PHP- Show Tables In Database</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a few people asking me how to <b class="pink">refresh a table (not the entire page) when inserting rows into a MySQL database</b>, so I thought I&#8217;d quickly put together a small demo.</p>
<p>Here&#8217;s a basic <a rel="nofollow" target="new" href="http://www.brightcherry.co.uk/code_examples/table_refresh/insert.php" title="Ajax JQuery / PHP - Refresh Table When Inserting Row Into a MySQL Database Demo">demo</a> of what I&#8217;m talking about. If you populate the form and press &#8220;Submit&#8221; you&#8217;ll notice the table updates without the entire page refreshing.</p>
<p><img src="http://www.brightcherry.co.uk/images/blogimages/ajax_table_refresh.jpg" title="Refresh Table When Inserting Row Into a MySQL Database" alt="Refresh Table When Inserting Row Into a MySQL Database" /></p>
<h4>Demo</h4>
<p><a rel="nofollow" target="new" href="http://www.brightcherry.co.uk/code_examples/table_refresh/insert.php" title="Ajax JQuery / PHP - Refresh Table When Inserting Row Into a MySQL Database Demo">Ajax JQuery / PHP &#8211; Refresh Table Demo</a>.</p>
<p>I&#8217;ve put a limit of 20 entries on the demo version, to save myself from being abused!!</p>
<h4>Download</h4>
<p><a rel="nofollow" target="new" href="http://brightcherry.co.uk/downloads/ajax_table_refresh_by_brightcherry.zip" title="Download Ajax JQuery / PHP - Refresh Table">Download Ajax JQuery / PHP &#8211; Refresh Table</a></p>
<p><strong>Please note</strong>, I have merely provided a guide. You are strongly advised to implement your own server and client side error checking.</p>
<p>I hope you find the code useful <img src='http://www.brightcherry.co.uk/scribbles/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2010/03/09/ajax-jquery-php-refresh-table-when-inserting-row-into-a-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP/MySQL- Escape All POST Or GET Variables For MySQL INSERT</title>
		<link>http://www.brightcherry.co.uk/scribbles/2010/02/16/phpmysql-make-all-post-or-get-variables-safe-for-mysql-insert/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2010/02/16/phpmysql-make-all-post-or-get-variables-safe-for-mysql-insert/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 19:26:58 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[MySQL & PHP]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=199</guid>
		<description><![CDATA[I&#8217;m quickly going to demonstrate how to escape special characters in a string for all POST/GET variables safe for a MySQL INSERT query when passing values from a HTML form.
So, let&#8217;s say we have a form like this on index.php:


Details


First Name:





Surname:





Email:










View Code HTML1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
&#60;form action=&#34;insert.php&#34; method=&#34;POST&#34;&#62;
&#60;fieldset&#62;
&#60;legend&#62;Details&#60;legend&#62;
&#60;div&#62;
&#60;label&#62;First Name:&#60;/label&#62;
&#60;/div&#62;
&#60;div&#62;
&#60;input type=&#34;input&#34; name=&#34;first_name&#34; value=&#34;Bright&#34; disabled=&#34;disabled&#34; /&#62;
&#60;/div&#62;
&#60;div&#62;
&#60;label&#62;Surname:&#60;/label&#62;
&#60;/div&#62;
&#60;div&#62;
&#60;input type=&#34;input&#34; name=&#34;surname&#34; value=&#34;Cherry&#34; disabled=&#34;disabled&#34; [...]


Related posts:<ol><li><a href='http://www.brightcherry.co.uk/scribbles/2008/12/04/html-form-effect-remove-default-value-on-focus/' rel='bookmark' title='Permanent Link: HTML Form Effect- Remove Default Value On Focus'>HTML Form Effect- Remove Default Value On Focus</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m quickly going to demonstrate how to escape special characters in a string for all POST/GET variables safe for a MySQL INSERT query when passing values from a HTML form.</p>
<p>So, let&#8217;s say we have a form like this on <b class="pink">index.php</b>:</p>
<form action="insert.php" method="POST">
<fieldset>
<legend>Details<br />
<legend>
<div>
<label>First Name:</label>
</div>
<div>
<input type="input" name="first_name" value="Bright" disabled="disabled" />
</div>
<div>
<label>Surname:</label>
</div>
<div>
<input type="input" name="surname" value="Cherry" disabled="disabled" />
</div>
<div>
<label>Email:</label>
</div>
<div>
<input type="input" name="email" value="design@brightcherry.co.uk" disabled="disabled" />
</div>
<div style="margin-top:10px;">
<input disabled="disabled" type="submit" value="Submit" />
</div>
</fieldset>
</form>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p199code5'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1995"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p199code5"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;insert.php&quot; method=&quot;POST&quot;&gt;
&lt;fieldset&gt;
&lt;legend&gt;Details&lt;legend&gt;
&lt;div&gt;
&lt;label&gt;First Name:&lt;/label&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;input&quot; name=&quot;first_name&quot; value=&quot;Bright&quot; disabled=&quot;disabled&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;label&gt;Surname:&lt;/label&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;input&quot; name=&quot;surname&quot; value=&quot;Cherry&quot; disabled=&quot;disabled&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;label&gt;Email:&lt;/label&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;input type=&quot;input&quot; name=&quot;email&quot; value=&quot;design@brightcherry.co.uk&quot; disabled=&quot;disabled&quot; /&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-top:10px;&quot;&gt;
&lt;input disabled=&quot;disabled&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/div&gt;
&lt;/fieldset&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>The form&#8217;s action is <b class="pink">insert.php</b>, so whichever method you choose (GET/POST) will get passed to insert.php. Now, before you INSERT the data into a MySQL table, you should ensure the data is safe to INSERT.</p>
<p>The PHP function you should use is <a href="http://php.net/manual/en/function.mysql-real-escape-string.php" title="PHP function: mysql_real_escape_string" rel="nofollow">mysql_real_escape_string</a>. </p>
<p>You can do the following before inserting the data (assuming the method type is POST):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p199code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1996"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p199code6"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'surname'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'surname'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>But that&#8217;s not a very efficient method because you&#8217;re repeating the same function over and over, and if the form you&#8217;re using has a lot more fields, it will quickly become very problematic for a number of reasons.</p>
<p>Here&#8217;s a better and more efficient way of cleaning the data:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p199code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1997"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p199code7"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So what&#8217;s happening now is that ALL the POST variables are being cleaned in the <b class="pink">foreach</b> loop. You&#8217;re also renaming the POST values to $clean, but keeping the actual key value the same &#8211; so to echo the values you simply do this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p199code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1998"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p199code8"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">echo</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'surname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>It&#8217;s as easy as that <img src='http://www.brightcherry.co.uk/scribbles/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2010/02/16/phpmysql-make-all-post-or-get-variables-safe-for-mysql-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; INSERT SELECT Example</title>
		<link>http://www.brightcherry.co.uk/scribbles/2010/02/14/mysql-insert-select-example/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2010/02/14/mysql-insert-select-example/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 11:01:47 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=196</guid>
		<description><![CDATA[I&#8217;m quickly going to demonstrate how to INSERT rows from one table into another table. I&#8217;d just like to clarify, this isn&#8217;t the same as completely copying a table, because with a INSERT SELECT query you can use the WHERE clause to INSERT rows with a particular condition (e.g. WHERE name = &#8216;Bill&#8217;). Whereas, copying [...]


Related posts:<ol><li><a href='http://www.brightcherry.co.uk/scribbles/2009/11/22/mysql-remove-duplicate-rows/' rel='bookmark' title='Permanent Link: MySQL- Remove Duplicate Rows'>MySQL- Remove Duplicate Rows</a></li><li><a href='http://www.brightcherry.co.uk/scribbles/2010/02/16/phpmysql-make-all-post-or-get-variables-safe-for-mysql-insert/' rel='bookmark' title='Permanent Link: PHP/MySQL- Escape All POST Or GET Variables For MySQL INSERT'>PHP/MySQL- Escape All POST Or GET Variables For MySQL INSERT</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m quickly going to demonstrate how to INSERT rows from one table into another table. I&#8217;d just like to clarify, this isn&#8217;t the same as completely copying a table, because with a INSERT SELECT query you can use the WHERE clause to INSERT rows with a particular condition (e.g. WHERE name = &#8216;Bill&#8217;). Whereas, copying an entire table will copy every single record.</p>
<h4>Table Structure</h4>
<p>This table is called <b class="pink">Postcode_tbl</b>:<br />
<img src="http://www.brightcherry.co.uk/images/mysql_duplicate/1.jpg" title="Postcode Table Structure" alt="Postcode Table Structure" /></p>
<h4>INSERT SELECT Query Example</h4>
<p>Let&#8217;s assume we have a table with the exact same structure as <b class="pink">Postcode_tbl</b>, but it&#8217;s called <b class="pink">Postcode_tbl_2</b>, and we want to copy all the rows from <b class="pink">Postcode_tbl</b> into <b class="pink">Postcode_tbl_2</b> where the first 2 characters of the postcode is &#8220;CM&#8221;.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p196code10'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19610"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p196code10"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span>
Postcode_tbl_2
<span style="color: #FF00FF;">&#40;</span>
postcode<span style="color: #FF00FF;">,</span>
longitude<span style="color: #FF00FF;">,</span>
latitude
<span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span>
postcode<span style="color: #FF00FF;">,</span>
longitude<span style="color: #FF00FF;">,</span>
latitude
<span style="color: #990099; font-weight: bold;">FROM</span>
Postcode_tbl
<span style="color: #990099; font-weight: bold;">WHERE</span>
postcode <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">'CM%'</span></pre></td></tr></table></div>

<p>Now, the table structure DOESN&#8217;T need to be the same in order to use a INSERT SELECT query. I just used the same structure for ease. If the table structure differs, or the field names don&#8217;t match, just make sure you specify the correct field names and order of fields in your query.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2010/02/14/mysql-insert-select-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL- Remove Duplicate Rows</title>
		<link>http://www.brightcherry.co.uk/scribbles/2009/11/22/mysql-remove-duplicate-rows/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2009/11/22/mysql-remove-duplicate-rows/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 12:25:50 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=189</guid>
		<description><![CDATA[I&#8217;ve been working with meduim sized tables (2.1million rows) in MySQL lately. One particular table had a lot of duplicate rows, which I needed to filter out. I&#8217;m quickly going to demonstrate how I did it. I&#8217;m sure there are many ways of doing this, but this method proved to be the easiest for me.
Example [...]


Related posts:<ol><li><a href='http://www.brightcherry.co.uk/scribbles/2010/02/14/mysql-insert-select-example/' rel='bookmark' title='Permanent Link: MySQL &#8211; INSERT SELECT Example'>MySQL &#8211; INSERT SELECT Example</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with meduim sized tables (2.1million rows) in MySQL lately. One particular table had a lot of duplicate rows, which I needed to filter out. I&#8217;m quickly going to demonstrate how I did it. I&#8217;m sure there are many ways of doing this, but this method proved to be the easiest for me.</p>
<h4>Example 1: Removing rows with a specific duplicate field:</h4>
<p>As you can see, the field &#8220;postcode&#8221; has duplicated rows.<br />
<img src="http://www.brightcherry.co.uk/images/mysql_duplicate/1.jpg" title="Duplicate MySQL field" alt="Duplicate MySQL field" /></p>
<h4>STEP 1: Copy table structure</h4>
<p>I used the following code to duplicate the table structure of `postcodes` (if you use PhpMyAdmin, you can use the shortcuts):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p189code14'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18914"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p189code14"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`DB_NAME`</span>.<span style="color: #008000;">`postcodes2`</span> <span style="color: #FF00FF;">&#40;</span>
<span style="color: #008000;">`postcodenospace`</span> <span style="color: #FF9900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">10</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF00FF;">,</span>
<span style="color: #008000;">`longitude`</span> <span style="color: #FF9900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">15</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF00FF;">,</span>
<span style="color: #008000;">`latitude`</span> <span style="color: #FF9900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">15</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span></pre></td></tr></table></div>

<h4>STEP 2: run query:</h4>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p189code15'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18915"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p189code15"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span>
postcodes2
<span style="color: #FF00FF;">&#40;</span>
postcode<span style="color: #FF00FF;">,</span>
longitude<span style="color: #FF00FF;">,</span>
latitude
<span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> postcode<span style="color: #FF00FF;">,</span>longitude<span style="color: #FF00FF;">,</span>latitude
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`postcodes`</span> 
<span style="color: #990099; font-weight: bold;">GROUP</span> <span style="color: #990099; font-weight: bold;">BY</span> postcode</pre></td></tr></table></div>

<p>That&#8217;s it. All the rows with a unique postcode will get inserted into the table &#8220;postcodes2&#8243;.</p>
<h4>The result</h4>
<p><img src="http://www.brightcherry.co.uk/images/mysql_duplicate/2.jpg" title="Duplicate MySQL field result" alt="Duplicate MySQL field result" /></p>
<p>The key is in the SELECT query, where the postcode field is grouped together. That effectively puts all the duplicate postcodes together,  generating a result of rows with unique postcodes.</p>
<h4>Example 2: Removing duplicate rows:</h4>
<h4>STEP 1: Copy table structure</h4>
<p>Use the code above to copy the table structure.</p>
<p>This example is slightly different, look at the data:</p>
<p><img src="http://www.brightcherry.co.uk/images/mysql_duplicate/3.jpg" title="Duplicate MySQL rows" alt="Duplicate MySQL rows" /></p>
<p>The previous example simply filtered the data by duplicate postcodes. As you can see, the highlighted row has different longitude and latitude values. So if you want to filter the data by unique rows, you need the following query:</p>
<h4>STEP 2: Run the query</h4>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p189code16'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18916"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p189code16"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span>
postcodes2
<span style="color: #FF00FF;">&#40;</span>
postcode<span style="color: #FF00FF;">,</span>
longitude<span style="color: #FF00FF;">,</span>
latitude
<span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> postcode<span style="color: #FF00FF;">,</span>longitude<span style="color: #FF00FF;">,</span>latitude
<span style="color: #990099; font-weight: bold;">FROM</span> <span style="color: #008000;">`postcodes`</span> 
<span style="color: #990099; font-weight: bold;">GROUP</span> <span style="color: #990099; font-weight: bold;">BY</span> <span style="color: #000099; font-weight: bold;">concat</span><span style="color: #FF00FF;">&#40;</span>postcode<span style="color: #FF00FF;">,</span>longitude<span style="color: #FF00FF;">,</span>latitude<span style="color: #FF00FF;">&#41;</span></pre></td></tr></table></div>

<h4>The result</h4>
<p><img src="http://www.brightcherry.co.uk/images/mysql_duplicate/4.jpg" title="Duplicate MySQL rows result" alt="Duplicate MySQL rows result" /></p>
<p>Again, the key is the SELECT query. This time the query groups all the fields together (using the CONCAT function), to return rows with completely unique values.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2009/11/22/mysql-remove-duplicate-rows/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Htaccess- 301 Redirect An Entire Directory / Folder</title>
		<link>http://www.brightcherry.co.uk/scribbles/2009/09/19/htaccess-301-redirect-an-entire-directory-folder/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/2009/09/19/htaccess-301-redirect-an-entire-directory-folder/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 23:07:00 +0000</pubDate>
		<dc:creator>Maruf</dc:creator>
				<category><![CDATA[htaccess fun]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=184</guid>
		<description><![CDATA[Here&#8217;s a simple pierce of code which will permanently redirect a folder / directory. For example, if you have a directory in the following path: http://www.example.com/pictures/, and for whatever reason decide to rename the directory to http://www.example.com/new-pictures/, the following htaccess code will safely redirect all users from /pictures/ to /new-pictures/
Redirect An Entire Directory / Folder [...]


Related posts:<ol><li><a href='http://www.brightcherry.co.uk/scribbles/2009/08/22/htaccess-prevent-people-hotlinking-your-images/' rel='bookmark' title='Permanent Link: Htaccess: Prevent People Hotlinking Your Images'>Htaccess: Prevent People Hotlinking Your Images</a></li><li><a href='http://www.brightcherry.co.uk/scribbles/2008/09/06/php-count-files-in-a-directory/' rel='bookmark' title='Permanent Link: PHP- Count Files In A Directory'>PHP- Count Files In A Directory</a></li><li><a href='http://www.brightcherry.co.uk/scribbles/2008/11/02/php-list-all-files-in-a-directory/' rel='bookmark' title='Permanent Link: PHP- List All Files In A Directory'>PHP- List All Files In A Directory</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple pierce of code which will permanently redirect a folder / directory. For example, if you have a directory in the following path: <b class="pink">http://www.example.com/pictures/</b>, and for whatever reason decide to rename the directory to <b class="pink">http://www.example.com/new-pictures/</b>, the following htaccess code will safely redirect all users from <b class="pink">/pictures/</b> to <b class="pink">/new-pictures/</b></p>
<h4>Redirect An Entire Directory / Folder with Htaccess</h4>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a rel="nofollow" href="javascript:;" onclick="javascript:showCodeTxt('p184code18'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18418"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p184code18"><pre class="php" style="font-family:monospace;">RewriteEngine on
RewriteBase <span style="color: #339933;">/</span>
RewriteRule ^old_dir<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span> http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.example.com/new_dir/ [R=301,L]</span></pre></td></tr></table></div>

<p>The nice thing about this code is that regardless of how deep you go into old_dir, it will always redirect. So literally the entire directory is redirected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/2009/09/19/htaccess-301-redirect-an-entire-directory-folder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
