<?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>Pressing the Red Button &#187; PHP</title>
	<atom:link href="http://www.pressthered.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pressthered.com</link>
	<description>Adventures in Software Development</description>
	<lastBuildDate>Sun, 08 Jan 2012 21:28:09 +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>How to Create an IE8 Accelerator</title>
		<link>http://www.pressthered.com/how_to_create_an_ie8_accelerator/</link>
		<comments>http://www.pressthered.com/how_to_create_an_ie8_accelerator/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 06:43:35 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[IE8]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=678</guid>
		<description><![CDATA[Accelerators in Internet Explorer 8 are a new feature that allows you to select text and perform actions on it (like look up a word, map an address, etc.). This tutorial creates an accelerator that lets you select a song title or artist and listen to the music.]]></description>
			<content:encoded><![CDATA[<p>Accelerators in Internet Explorer 8 are a new feature that allows you to select text and perform actions on it (like look up a word, map an address, etc.). This tutorial creates an accelerator that lets you select a song title or artist and listen to the music.</p>
<div id="attachment_682" class="wp-caption aligncenter" style="width: 326px"><img src="http://www.pressthered.com/wp-content/uploads/2009/11/contextmenu.jpg" alt="IE 8 Context Menu" title="Listen To Music Preview" width="316" height="189" class="size-full wp-image-682" /><p class="wp-caption-text">IE 8 Context Menu</p></div>
<p>Code is included that utilizes a JQuery front-end against a PHP webservice. To get the demo working on your own machine, some familiarity with JQuery and PHP is required.<br />
<strong><br />
Try The Demo</strong></p>
<p>If you are using IE8, you can install the demo with this link:</p>
<p><a href="#" onclick="window.external.AddService('http://www.pressthered.com/musiclookup/lookup.xml');return false;">Install &#8220;Listen To Music&#8221; Accelerator</a></p>
<p>You will get the message below, check the &#8220;Make this my default&#8230;&#8221;, and click Add.<br />
<div id="attachment_683" class="wp-caption aligncenter" style="width: 405px"><img src="http://www.pressthered.com/wp-content/uploads/2009/11/install.jpg" alt="Install Popup" title="install" width="395" height="289" class="size-full wp-image-683" /><p class="wp-caption-text">Add Accelerator Popup</p></div></p>
<p>Once you have it installed it, you can select text on a web page and right click to bring up the menu. Hover over &#8220;Listen to Music&#8221; for a selection of available songs.<br />
contextmenu</p>
<p><strong>Try it out by selecting an artist or title below:</strong></p>
<p><i>Michael Jackson seems to be popular, and who doesn&#8217;t know Thriller.</i></p>
<p>Once a song is selected, you are forwarded to the <a href="http://www.grooveshark.com">GrooveShark</a> site where you can listen to the full song for free. </p>
<p><strong><br />
The Tutorial</strong></p>
<p><strong>Step 1: Set Up Your Development Environment</strong></p>
<p>You will need a web server that runs PHP (Apache or IIS will work). Create a virtual directory called &#8220;musiclookup&#8221;. Copy all the files included in the <a href="/musiclookup/musiclookup-source.zip">tutorial code</a> to the &#8220;musiclookup&#8221; directory you created. In this demo, we use localhost as the server, if you have another server name, you can manually update the references to localhost in the code.</p>
<p><strong>Step 2: Testing your Environment</strong></p>
<p>Now you have to test that the code works on your own machine and the rest of the steps are a breeze. Test the lookup page by going to:</p>
<p><em>http://localhost/musiclookup/lookup.html?s=Thriller</em></p>
<p>If a song list appears, then you are good to go:<br />
<div id="attachment_687" class="wp-caption aligncenter" style="width: 545px"><img src="http://www.pressthered.com/wp-content/uploads/2009/11/testclient.jpg" alt="This is what should appear when testing your local install." title="Test" width="535" height="386" class="size-full wp-image-687" /><p class="wp-caption-text">This is what should appear when testing your local install.</p></div></p>
<p>If you don&#8217;t get the song list, there are some troubleshooting tips in the trouble.txt file included in the source. </p>
<p><strong>Step 3: Creating Your Accelerator Installation File</strong></p>
<p>IE Accelerators are installed by reading a specially formatted XML file. We are going use a modified version of the default installation file that Microsoft provides: </p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;os:openServiceDescription
    xmlns:os="http://www.microsoft.com/schemas/openservicedescription/1.0">
    &lt;os:homepageUrl>http://localhost/musiclookup&lt;/os:homepageUrl>
    &lt;os:display>
        &lt;os:name>Listen to Music&lt;/os:name>
        &lt;os:icon>http://localhost/musiclookup/favicon.ico&lt;/os:icon>
        &lt;os:description>Listen to music using GrooveShark's TinySong api.&lt;/os:description>
    &lt;/os:display>
    &lt;os:activity category="Listen">
        &lt;os:activityAction context="selection">
            &lt;os:preview action="http://localhost/musiclookup/lookup.html?s={selection}" />
            &lt;os:execute action="http://localhost/musiclookup/goto.php" method="get">
                &lt;os:parameter name="s" value="{selection}" type="text" />
            &lt;/os:execute>
        &lt;/os:activityAction>
    &lt;/os:activity>
&lt;/os:openServiceDescription> 
</pre>
<p>We&#8217;ll start by editing the basic details. Open the file called lookup.xml in the musiclookup folder you created and review the following settings:</p>
<ul>
<li><b>homepageUrl</b>: Modify this url if you used a server other than localhost.</li>
<li><b>name</b>: Change the name to &#8220;My Music Lookup&#8221; (or some other custom name)</li>
<li><b>icon</b>: The url of an icon that is displayed in the context menu. You can leave this.</li>
<li><b>description</b>: A simple description can be entered here. You can leave this also.</li>
</ul>
<p><strong>Step 4: Setting up the Preview Action</strong></p>
<p>The preview action is the url that will display the preview page:</p>
<pre>
&lt;os:preview action="http://localhost/musiclookup/lookup.html?s={selection}" />
</pre>
<p>We tested the preview page in step 2, so you can use the url here (unless you have a server name). One item to note is the &#8220;{selection}&#8221; text. This text is replaced with what the user selected when your preview page is displayed. Your preview page can then read this url variable and act on it. More url variables can be found in <a href="http://msdn.microsoft.com/en-us/library/cc289775(VS.85).aspx">Micrsoft&#8217;s documentation</a>.</p>
<p><strong>Step 5: Setting up the Execute Action</strong></p>
<p>The execute action is the url that you are forwarded to when you click the context menu.:</p>
<pre>
&lt;os:execute action="http://localhost/musiclookup/goto.php" method="get">
  &lt;os:parameter name="s" value="{selection}" type="text" />
&lt;/os:execute>
</pre>
<p>In our case we use a simple php page to redirect to the third party site that plays the music.</p>
<p><strong>Step 6: Testing Your Accelerator</strong></p>
<p>To test your accelerator, you must create a link to install it. A special Microsoft javascript function is used to call your xml file. You can see an example of this in the test.html file in the musiclookup folder:<br />
<div id="attachment_681" class="wp-caption aligncenter" style="width: 510px"><img src="http://www.pressthered.com/wp-content/uploads/2009/11/testpage.jpg" alt="Here you can test your accelerator." title="Test Page" width="500" class="size-full wp-image-681" /><p class="wp-caption-text">Here you can test your accelerator.</p></div></p>
<p>Once you have it installed, you can select text on your page and see the preview. If you want to make changes to the configuration file, you can reinstall by simply clicking your install link again. You can also manually remove an Accelerator by going to the &#8220;Tools -> Manage Add-ons&#8221; menu item.</p>
<p><strong>How The JQuery Front End Works:</strong><br />
What is neat about the preview action, is that it brings up a mini page that can run html and javascript like any other page. The preview page is a html page that references JQuery to call the web service and get some simple animation effects.</p>
<p><strong>How the PHP Web Service Works:</strong><br />
The php code calls GrooveShark&#8217;s service (tinysong.com). It is a RESTful interface that returns results in plain text. The php code parses the results and reformats them into json to make it easier to use by the front end. The php web service also acts as a proxy because your preview page can not call a web service (<a href="http://tinysong.com">tinysong</a>) from another domain.</p>
<p><strong>Making Improvements</strong><br />
There is certainly room for new feature and improvement. The preview page could be modified to include additional information or pull data from additional sources. While Grooveshark does not allow using their music player widgets, other services do (like Amazon, Real Networks or iTunes). The back end could be modified to pull from their web services and listen to the music directly on the preview page (although you don&#8217;t get to listen to the full song like you do when going to GrooveShark&#8217;s site).</p>
<p><strong>The End</strong><br />
I hope you enjoyed the tutorial and that you get some use out of the accelerator. Feel free to ask any questions or make any suggestions. </p>
<p><strong>Additional Resources</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/cc289775(VS.85).aspx">Microsoft&#8217;s Documentation on Accelerators</a></li>
<li><a href="http://www.grooveshark.com/">GrooveShark</a></li>
<li><a href="http://apidocs.tinysong.com/">TinySong API Documentaion</a></li>
<li><a href="http://jquery.com/">JQuery</a></li>
<li><a href="http://developer.yahoo.com/php/howto-parseRestPhp.html">Parsing REST Results in PHP</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/how_to_create_an_ie8_accelerator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting MimeType in PHP</title>
		<link>http://www.pressthered.com/setting_mimetype_in_php/</link>
		<comments>http://www.pressthered.com/setting_mimetype_in_php/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 06:38:54 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[mimetype]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=290</guid>
		<description><![CDATA[Setting the Mime Type allows you to tell the browser what type of response that it is going to receive. This is useful for returning non html results like file downloads, xml and JSON. //Setting a XML File Type in PHP $mtype = "text/xml"; header("Content-Type: " . $mtype); //Setting a File Download Type in PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Setting the Mime Type allows you to tell the browser what type of response that it is going to receive. This is useful for returning non html results like file downloads, xml and JSON.</p>
<pre name="code" class="php">
//Setting a XML File Type in PHP
$mtype = "text/xml";
header("Content-Type: " . $mtype);

//Setting a File Download Type in PHP
$mtype = "application/octet-stream";
header("Content-Type: " . $mtype);

//Setting a JSON results type in PHP
$mtype = "application/javascript";
header("Content-Type: " . $mtype);
</pre>
<p>Here is a list of common mime types:<br />
<strong>Javascript </strong>- application/javascript<br />
<strong>Java</strong> &#8211; application/x-java-applet<br />
<strong>Java</strong> &#8211;  application/x-java-bean<br />
<strong>Java</strong> &#8211; application/x-java-vm<br />
<strong>Flash</strong> &#8211; application/x-shockwave-flash<br />
<strong>MP3</strong> &#8211; audio/mp3<br />
<strong>JPEG</strong> &#8211; image/jpeg<br />
<strong>JPG</strong> &#8211; image/jpg<br />
<strong>GIF</strong> &#8211; image/gif<br />
<strong>PNG</strong> &#8211; image/png<br />
<strong>HTML</strong> &#8211;  text/html<br />
<strong>CSS</strong> &#8211; text/css<br />
<strong>Text File</strong> &#8211; text/plain<br />
<strong>XML</strong> &#8211; text/xml<br />
<strong>Video AVI</strong> &#8211; video/avi<br />
<strong>Video Microsoft</strong> &#8211; video/msvideo<br />
<strong>Video QuickTime</strong> &#8211; video/quicktime<br />
<strong>Video DIVX</strong> &#8211; video/divx<br />
<strong>File Download</strong> &#8211; application/octet-stream</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/setting_mimetype_in_php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Install PHP CURL on IIS</title>
		<link>http://www.pressthered.com/how_to_install_php_curl_on_iis/</link>
		<comments>http://www.pressthered.com/how_to_install_php_curl_on_iis/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 06:35:11 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=280</guid>
		<description><![CDATA[Are you getting this error: Fatal error: Call to undefined function curl_init() in C:\myfile.php on line 100 A quick overview on how to get the php_curl.dll working on IIS. This works with PHP 5.x on Windows. Most likely you did not install the CURL extension when you first installed PHP on your machine. Below is [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Are you getting this error:</strong><br />
<em>Fatal error: Call to undefined function curl_init() in C:\myfile.php on line 100</em></p>
<p>A quick overview on how to get the php_curl.dll working on IIS. This works with PHP 5.x on Windows. Most likely you did not install the CURL extension when you first installed PHP on your machine. Below is the easiest method to install any missing extensions (like CURL):</p>
<ol>
<li>Go to Add/Remove Programs in Control Panel, Find the PHP 5 installation in the list and click Change.</li>
<li>When the installer comes up, click Change<br />
<div id="attachment_282" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.pressthered.com/wp-content/uploads/2009/06/curl1-300x237.gif" alt="Changing Your PHP Installation to Install an Extension" title="Changing Your PHP Installation to Install an Extension" width="300" height="237" class="size-medium wp-image-282" /><p class="wp-caption-text">Changing Your PHP Installation to Install an Extension</p></div>
</li>
<li>
Find Curl in the list of extensions and click OK to save and finish the installation<br />
<div id="attachment_281" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.pressthered.com/wp-content/uploads/2009/06/curl2-300x236.gif" alt="Installing CURL using the PHP Installer" title="Installing CURL using the PHP Installer" width="300" height="236" class="size-medium wp-image-281" /><p class="wp-caption-text">Installing CURL using the PHP Installer</p></div>
</li>
<li>Restart IIS (from command Prompt, type &#8220;iisreset&#8221;). Now curl should be working for you.
</li>
</ol>
<p>This is much easier that having to find the dll yourself and modifying the php.ini file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/how_to_install_php_curl_on_iis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Hacks: Sequentially Numbering Records</title>
		<link>http://www.pressthered.com/sql_hacks_sequentially_numbering_records/</link>
		<comments>http://www.pressthered.com/sql_hacks_sequentially_numbering_records/#comments</comments>
		<pubDate>Mon, 11 Dec 2006 19:45:34 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.pressingtheredbutton.com/sql_hacks_sequentially_numbering_records/</guid>
		<description><![CDATA[It is a simple concept, I want each record of a SQL result set to be numbered 1 through X. Well SQL wasn't really designed to do this so here come some the ugliest hacks you'll every see to "just get it done". Here is some more background. I got contracted to write some fixes [...]]]></description>
			<content:encoded><![CDATA[<p>It is a simple concept, I want each record of a SQL result set to be numbered 1 through X. Well SQL wasn't really designed to do this so here come some the ugliest hacks you'll every see to "just get it done".</p>
<p>Here is some more background. I got contracted to write some fixes for an existing ecommerce web site written in PHP/MySQL.  One of those fixes was a bug that occurred when trying to sort the store's products in the admin interface. Each product had a sort order that could be manually adjusted using these up and down arrows. Common approach, but it wasn't implemented well. I'm not going to go into any more details, but the simple fix was to create a function that could reset the sort when needed.</p>
<p>I wanted a quick way to regenerate the sort order numbers based on the SQL result set. I did some googling and found this link pertaining to Microsoft SQL Server.:<br />
<a href="http://www.databasejournal.com/features/mssql/article.php/10894_2244821_1">Database Journal Article</a></p>
<p>These methods could be modified to work with MySQL but I needed something more elegant. I found my solution in the least likely of places, <a href="http://dev.mysql.com/doc/refman/4.1/en/update.html">the manual</a>.</p>
<p><strong>Displaying Sequential Numbers in MySQL:</strong></p>
<div class="igBar"><span id="lsql-4"><a href="#" onclick="javascript:showPlainTxt('sql-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-4">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SET</span> @rnk=<span style="color: #cc66cc;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> id, @rnk:=@rnk+<span style="color: #cc66cc;color:#800000;">1</span> <span style="color: #993333; font-weight: bold;">AS</span> product_order</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">FROM</span> products <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> product_name; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now for the let down. It won't work in PHP 4/MySQL. This is typical when working in LAMP. You develop code locally, go to move it to the client's machine and they have minor versions differences and your code doesn't work. The solution above requires two SQL statements and the PHP MySQL library does not allow the running of multiple queries at the same time (to prevent SQL injection attacks). Supposedly it will work in PHP 5/MySQL with the mysqli_multi_query but I didn't have time to test.</p>
<p>Since excuses don't pay the bills, I had to resort to an ugly hack (as opposed to elegant hack). I didn't really like the methods in the Database Journal link above so I made my own:</p>
<p><strong>Displaying Sequential numbers in MySQL/PHP4:</strong><br />
The basic idea behind this one is to use a seperate table to update the sort order.<br />
1. Create a Sort Table</p>
<div class="igBar"><span id="lsql-5"><a href="#" onclick="javascript:showPlainTxt('sql-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-5">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`sort_order`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`id`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">11</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff0000;">`order`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;color:#800000;">11</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">`order`</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>2. Run the SQL that will update the sort</p>
<div class="igBar"><span id="lsql-6"><a href="#" onclick="javascript:showPlainTxt('sql-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-6">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#first clear the table</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">TRUNCATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> sort_order;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#reset the auto increment</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> sort_order <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>=<span style="color: #cc66cc;color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#insert the id's of the records sorted the way you want</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> sort_order <span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> id <span style="color: #993333; font-weight: bold;">FROM</span> products <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> product_order;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#update the sort order field</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">UPDATE</span> products p</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sort_order so <span style="color: #993333; font-weight: bold;">ON</span> p.id = so.id</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SET</span> p.product_order = so.<span style="color: #993333; font-weight: bold;">ORDER</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This was a quick and dirty hack but it worked for the situation. For multi-user use, I would put the statements in a transaction.</p>
<p>Let me know if you have any questions or come up with anything else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/sql_hacks_sequentially_numbering_records/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

