<?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"
	>

<channel>
	<title>James Tombs</title>
	<atom:link href="http://www.p4th3t1c.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://jamestombs.co.uk</link>
	<description>Development blog from James Tombs about PHP, XHTML + CSS,Drupal and Wordpress</description>
	<pubDate>Fri, 31 Oct 2008 07:02:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Another spammer - 65.94.2.210</title>
		<link>http://jamestombs.co.uk/2008-10-31/another-spammer-65942210/951</link>
		<comments>http://jamestombs.co.uk/2008-10-31/another-spammer-65942210/951#comments</comments>
		<pubDate>Fri, 31 Oct 2008 07:02:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PCs]]></category>

		<category><![CDATA[address]]></category>

		<category><![CDATA[ip]]></category>

		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=951</guid>
		<description><![CDATA[Another spammer caught in action.
Some others that have come up:

94.102.60.43
94.102.60.77
94.102.60.39

]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Another spammer caught in action.</p>
<p>Some others that have come up:</p>
<ul>
<li>94.102.60.43</li>
<li>94.102.60.77</li>
<li>94.102.60.39</li>
</ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-31/another-spammer-65942210/951/feed</wfw:commentRss>
		</item>
		<item>
		<title>[Drupal] Deleting node content of a certain type in bulk</title>
		<link>http://jamestombs.co.uk/2008-10-27/drupal-deleting-node-content-of-a-certain-type-in-bulk/944</link>
		<comments>http://jamestombs.co.uk/2008-10-27/drupal-deleting-node-content-of-a-certain-type-in-bulk/944#comments</comments>
		<pubDate>Mon, 27 Oct 2008 10:48:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[array]]></category>

		<category><![CDATA[array type]]></category>

		<category><![CDATA[content type]]></category>

		<category><![CDATA[data]]></category>

		<category><![CDATA[downloads]]></category>

		<category><![CDATA[drupal]]></category>

		<category><![CDATA[hook menu]]></category>

		<category><![CDATA[input format]]></category>

		<category><![CDATA[long time]]></category>

		<category><![CDATA[menu function]]></category>

		<category><![CDATA[nid]]></category>

		<category><![CDATA[node]]></category>

		<category><![CDATA[object result]]></category>

		<category><![CDATA[occasions]]></category>

		<category><![CDATA[page]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[result set]]></category>

		<category><![CDATA[set time]]></category>

		<category><![CDATA[time limit]]></category>

		<category><![CDATA[urls]]></category>

		<category><![CDATA[variables]]></category>

		<category><![CDATA[www domain]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=944</guid>
		<description><![CDATA[On occasions you may need to bulk delete all nodes of a certain type.
The following code requires 2 variables, the amount of rows to delete each time and the content type.

$amount = 100;
$type = 'node_type';
$result = db_query&#40;&#34;SELECT nid FROM {node} WHERE type = '%s' LIMIT %d&#34;, $type, $amount&#41;;
if &#40;db_num_rows&#40;$result&#41; &#38;&#38; user_access&#40;'administer nodes'&#41;&#41; &#123;
  $n [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>On occasions you may need to bulk delete all nodes of a certain type.</p>
<p>The following code requires 2 variables, the amount of rows to delete each time and the content type.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$amount</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span>;
<span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="">'node_type'</span>;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> db_query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT nid FROM {node} WHERE type = '%s' LIMIT %d&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>db_num_rows<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> user_access<span style="color: #009900;">&#40;</span><span style="">'administer nodes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> db_fetch_object<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>;
    node_delete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nid</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000088;">$n</span>++;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$n</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    drupal_goto<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  drupal_set_message<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="">'No entries found for node type @type, or you do not have permission to modify nodes.'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'@type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will go through all the nodes of the type you define and delete the node.  Once finished doing the batch, the page is then redirected back to the same page to delete another batch.</p>
<p>This can be placed in a node with an Input format of PHP code or through a module.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> modulename_menu<span style="color: #009900;">&#40;</span><span style="color: #000088;">$may_cache</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$may_cache</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="">'path'</span> <span style="color: #339933;">=&gt;</span> <span style="">'this/is/the/path'</span><span style="color: #339933;">,</span>
      <span style="">'callback'</span> <span style="color: #339933;">=&gt;</span> <span style="">'modulename_delete'</span><span style="color: #339933;">,</span>
      <span style="">'access'</span> <span style="color: #339933;">=&gt;</span> user_access<span style="color: #009900;">&#40;</span><span style="">'administer nodes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="">'title'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="">'Delete Nodes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$items</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then wrap the above deletion code into a function such as:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> modulename_delete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="">'node_type'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then you can navigate to the path in the hook_menu function and start the batch deletion.  To delete other types of nodes, add the content type to the end of the url. For events it would be:</p>
<p>http://www.domain.com/<strong>this/is/the/path/event</strong></p>
<p>Depending on what modules you have enabled, this can take a long time as the node_delete function calls a module_invoke function for any module to interact with it.  If you have a lot of modules this will take a long time.</p>
<p>Alternatively you can download and install the <a href="http://drupal.org/project/delete_all" onclick="javascript:pageTracker._trackPageview('/outbound/article/drupal.org');">Delete all module</a> which serves the same function.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-27/drupal-deleting-node-content-of-a-certain-type-in-bulk/944/feed</wfw:commentRss>
		</item>
		<item>
		<title>Built my first HTPC (Home Theatre Personal Computer)</title>
		<link>http://jamestombs.co.uk/2008-10-26/built-my-first-htpc-home-theatre-personal-computer/938</link>
		<comments>http://jamestombs.co.uk/2008-10-26/built-my-first-htpc-home-theatre-personal-computer/938#comments</comments>
		<pubDate>Sun, 26 Oct 2008 11:31:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PCs]]></category>

		<category><![CDATA[120mm fans]]></category>

		<category><![CDATA[acceleration]]></category>

		<category><![CDATA[amd]]></category>

		<category><![CDATA[amplifier]]></category>

		<category><![CDATA[analogue]]></category>

		<category><![CDATA[audio]]></category>

		<category><![CDATA[be]]></category>

		<category><![CDATA[chip]]></category>

		<category><![CDATA[consumers]]></category>

		<category><![CDATA[crossfire]]></category>

		<category><![CDATA[detailer]]></category>

		<category><![CDATA[displayed]]></category>

		<category><![CDATA[dvd]]></category>

		<category><![CDATA[dvi]]></category>

		<category><![CDATA[fan speed]]></category>

		<category><![CDATA[film]]></category>

		<category><![CDATA[front]]></category>

		<category><![CDATA[game]]></category>

		<category><![CDATA[games]]></category>

		<category><![CDATA[gigabyte ga]]></category>

		<category><![CDATA[graphics card]]></category>

		<category><![CDATA[graphics technology]]></category>

		<category><![CDATA[harddrive]]></category>

		<category><![CDATA[hardware acceleration]]></category>

		<category><![CDATA[hdmi]]></category>

		<category><![CDATA[hell]]></category>

		<category><![CDATA[htpc case]]></category>

		<category><![CDATA[image]]></category>

		<category><![CDATA[images]]></category>

		<category><![CDATA[join]]></category>

		<category><![CDATA[lcd display]]></category>

		<category><![CDATA[micro atx]]></category>

		<category><![CDATA[news]]></category>

		<category><![CDATA[performance levels]]></category>

		<category><![CDATA[product]]></category>

		<category><![CDATA[radeon]]></category>

		<category><![CDATA[realtek chip]]></category>

		<category><![CDATA[reviewers]]></category>

		<category><![CDATA[rubber grommets]]></category>

		<category><![CDATA[sound]]></category>

		<category><![CDATA[ventilation holes]]></category>

		<category><![CDATA[vibration]]></category>

		<category><![CDATA[vista]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=938</guid>
		<description><![CDATA[The idea of an HTPC is to have a PC that can fit in with your amplifier/receiver underneath your TV which will act as a DVD player but with more features.
Hardware wise it is identical to a normal PC with CPU, RAM, motherboard etc etc but generally put in to more stylish cases specially built [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>The idea of an HTPC is to have a PC that can fit in with your amplifier/receiver underneath your TV which will act as a DVD player but with more features.</p>
<p>Hardware wise it is identical to a normal PC with CPU, RAM, motherboard etc etc but generally put in to more stylish cases specially built to fit in most TV stands.</p>
<div class="amazon"><a href="http://www.amazon.co.uk/Antec-VERIS-Fusion-Remote-Black/dp/B001F10526%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB001F10526" ><img src="http://ecx.images-amazon.com/images/I/2170tLUiMcL._SL75_.jpg" /></a></div>
<p><strong>Case</strong></p>
<p>I opted for an <a href="http://www.antec.com/usa/productDetails.php?lan=us&#038;id=15739" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.antec.com');">Antec Fusion Black HTPC</a> case which is a fairly nice case, although it can be seen as quite costly at around £100 without a PSU. The case is steal with an aluminium front but even so it doesn&#8217;t weigh alot.  There is space for 2 hard drives which are secured with rubber grommets to stop vibration and 2 5.25&#8243; slots with one of these slots being used for the LCD display that comes built with the case, but can be taken out. The case has a few ventilation holes around to keep components cool but only has 2 120mm fans which are located on the side of the case near where the CPU will be.  Both of these fans are Antec Tri-Cools and as such have the 3 way setting for fan speed, low, medium, high.  I have mine set to low which gives off a little bit of noise and gives more than adequate cooling for the rest of the components.</p>
<div class="amazon">
<a href="http://www.amazon.co.uk/Gigabyte-GA-MA78GM-S2H-780G-Sockel-AM2/dp/B0015IXBG6%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0015IXBG6" ><img src="http://ecx.images-amazon.com/images/I/315ToqpBOrL._SL75_.jpg" /></a></div>
<p><strong>Motherboard</strong></p>
<p>After reading many good reviews I bought the <a href="http://www.gigabyte.com.tw/Products/Motherboard/Products_Overview.aspx?ProductID=2758" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.gigabyte.com.tw');">Gigabyte GA-MA78GM-S2H AMD 780G Micro-ATX</a>.  The GA-MA78GM-S2H uses the AMD 780G chipset which has onboard audio and graphics.  The onboard audio is a Realtek chip with your standard analogue in and outs but also has a digital out.  The onboard graphics is called the Radeon HD 3200 which is said to be equal in performance to the Radeon HD 3450.  The HD 3200 has AVIVO and allows for full hardware acceleration if the software supports it.  The HD 3200 gives you VGA, DVI and HDMI which also carries sound. The motherboard also has a feature called Hybrid Graphics Technology. This allows you to put in another graphics card in to the PCI-e 2.0 slot which will be used in a crossfire like situation although AMD refuses to call it crossfire due to the performance levels not being the same. Unfortunately you can just shove any card in there and get this performance.  It is obviously limited to AMD/ATi cards only and even then it will only use the power equivalent to the onboard graphics.  In this case the best card to put in would be the HD 3450.</p>
<div class="amazon">
<a href="http://www.amazon.co.uk/AMD-Athlon-Efficient-Dual-Core-Processor/dp/B0017K9F44%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0017K9F44" ><img src="http://ecx.images-amazon.com/images/I/31kGNZEA7VL._SL75_.jpg" /></a>
</div>
<p><strong>CPU</strong></p>
<p>Keeping to an all AMD affair, I got the AMD Athlon X2 4850e which is a low power CPU said to consume only 45W.  This also reduces heat which is a top priority in an HTPC as it means you don&#8217;t need a noisy fan on it, and this CPU is more than capable of processing any HD media or x264 rips.</p>
<div class="amazon"><a href="http://www.amazon.co.uk/Corsair-XMS2-Xtreme-Performance-PC2-6400/dp/B000EMP2MU%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000EMP2MU" ><img src="http://ecx.images-amazon.com/images/I/21ATDADE8ML._SL75_.jpg" /></a></div>
<p><strong>RAM</strong></p>
<p>RAM isn&#8217;t used that much in an HTPC compared to a gaming PC so I just got 2GB (2x 1GB sticks) of <a href="http://www.corsairmemory.com/products/xms2.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.corsairmemory.com');">Corsair DDR2 XMS2 PC2-6400C5 TwinX</a>.  Of course you can easily change this to 4GB if you want.</p>
<div class="amazon"><a href="http://www.amazon.co.uk/Corsair-EPS12V-Modular-Version-CMPSU-520HXUK/dp/B000RW8SJ6%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000RW8SJ6" ><img src="http://ecx.images-amazon.com/images/I/51SCyNwFFYL._SL75_.jpg" /></a></div>
<p><strong>PSU</strong></p>
<p>As I was happy with my current Corsair PSU in my gaming PC I chose to keep my loyalty and got the Corsair CX400W which is more than capable of powering the HTPC with room to spare if I ever wanted to add a new sound card or new graphics card.</p>
<div class="amazon"><a href="http://www.amazon.co.uk/Samsung-Spinpoint-500GB-7200RPM-SATA300/dp/B00187WT44%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00187WT44" ><img src="http://ecx.images-amazon.com/images/I/41MOJH0hshL._SL75_.jpg" /></a></div>
<p><strong>Hard drive</strong></p>
<p>Being a Samsung fan due to the low noise from their Spinpoint harddrives, I bought another Samsung SpinPoint F1 500GB to join my growing collection of them.  This drive isn&#8217;t particularly slow, but obviously won&#8217;t keep up with a Western Digital Raptor but is a hell of a lot quieter.  This only used up 1 slot, so I still have another slot spare to add another drive in the future if I wanted to.</p>
<div class="amazon"><a href="http://www.amazon.co.uk/LG-GGC-H20L-DVDRW-DVD-ROM-retail/dp/B000XH402E%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB000XH402E" ><img src="http://ecx.images-amazon.com/images/I/31zC89zoj5L._SL75_.jpg" /></a></div>
<p><strong>DVD Drive</strong></p>
<p>Originally I was just going to buy a £20 DVD drive. But then I saw the <a href="http://uk.lge.com/products/model/detail/bluray_ggch20l.jhtml" onclick="javascript:pageTracker._trackPageview('/outbound/article/uk.lge.com');">LG GGC-H20L Blu-Ray Reader &#038; HD-DVD ROM</a>. For only £45 more I now have the ability to play Blu-Ray and HD-DVD. Although HD-DVD has been beaten by Blu-Ray there is still a lot of HD-DVD stock out there with stores trying to get rid of it.  So when you have the choice of getting HD films for as little as £3 it seemed obvious to get a dual player.  The only thing I forgot to check about this drive before purchasing was the noise, but I was gladly surprised with in once it was installed.  Although not quiet, it wasn&#8217;t too noticeable, so when you have a film on you are unlikely to hear it.</p>
<div class="amazon"><a href="http://www.amazon.co.uk/Vista-Home-Premium-SP1-64-bit/dp/B0015CCFLE%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0015CCFLE" ><img src="http://ecx.images-amazon.com/images/I/519c9W3WY-L._SL75_.jpg" /></a></div>
<p><strong>Software</strong></p>
<p>At the moment, I don&#8217;t have any dedicated software for my HTPC but I have got Windows Vista Home Premium 64-bit to install, then I can test with further software to expand the HTPC to be the optimum it can be.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-26/built-my-first-htpc-home-theatre-personal-computer/938/feed</wfw:commentRss>
		</item>
		<item>
		<title>AVG and OpenDNS bring up some bad suggestions on searches</title>
		<link>http://jamestombs.co.uk/2008-10-25/avg-and-opendns-bring-up-some-bad-suggestions-on-searches/933</link>
		<comments>http://jamestombs.co.uk/2008-10-25/avg-and-opendns-bring-up-some-bad-suggestions-on-searches/933#comments</comments>
		<pubDate>Sat, 25 Oct 2008 06:25:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<category><![CDATA[avg]]></category>

		<category><![CDATA[chrome]]></category>

		<category><![CDATA[co uk]]></category>

		<category><![CDATA[dns record]]></category>

		<category><![CDATA[first thoughts]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[ie7]]></category>

		<category><![CDATA[isp]]></category>

		<category><![CDATA[mail]]></category>

		<category><![CDATA[problem]]></category>

		<category><![CDATA[problems]]></category>

		<category><![CDATA[search engines]]></category>

		<category><![CDATA[search feature]]></category>

		<category><![CDATA[search recommendations]]></category>

		<category><![CDATA[spam]]></category>

		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=933</guid>
		<description><![CDATA[On a computer with IE7 and the AVG toolbar I tried to go to mail.google.co.uk, which it turns out doesn&#8217;t exist.  So as no DNS record is found, the address is sent off to Yahoo.  AVGs partner, then it gives some suggested results of what I may be looking for, but the results [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>On a computer with IE7 and the AVG toolbar I tried to go to mail.google.co.uk, which it turns out doesn&#8217;t exist.  So as no DNS record is found, the address is sent off to Yahoo.  AVGs partner, then it gives some suggested results of what I may be looking for, but the results it gave certainly weren&#8217;t child friendly.</p>
<p><a href="http://jamestombs.co.uk/wp-content/uploads/2008/10/avg_toolbar_yahoo.jpg" ><img src="http://jamestombs.co.uk/wp-content/uploads/2008/10/avg_toolbar_yahoo.jpg" alt="" title="avg_toolbar_yahoo" width="500" height="254" class="alignnone size-full wp-image-934" /></a></p>
<p>My first thoughts, were that, that was very wrong from Yahoo.  So I tried it on another PC with Chrome and had been set up to use OpenDNS as the ISP&#8217;s DNS kept going down and having problems.</p>
<p><a href="http://jamestombs.co.uk/wp-content/uploads/2008/10/open_dns_google.jpg" ><img src="http://jamestombs.co.uk/wp-content/uploads/2008/10/open_dns_google.jpg" alt="" title="open_dns_google" width="500" height="471" class="alignnone size-full wp-image-935" /></a></p>
<p>Quite clearly not a one off on the AVG results.  The fact that they are so similar, either AVG toolbar uses Google for the search recommendations and Yahoo for the actual search feature or some SEO sites are spamming the keywords and getting some recommended words to the top of all search engines.</p>
<p>Either way it is inappropriate and you wouldn&#8217;t expect this, least of all when searching for something to do with Google itself.  Perhaps they better put a redirect in for mail.google.co.uk to mail.google.com.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-25/avg-and-opendns-bring-up-some-bad-suggestions-on-searches/933/feed</wfw:commentRss>
		</item>
		<item>
		<title>[FPSS] Front Page Slideshow for Drupal Update</title>
		<link>http://jamestombs.co.uk/2008-10-24/fpss-front-page-slideshow-for-drupal-update/927</link>
		<comments>http://jamestombs.co.uk/2008-10-24/fpss-front-page-slideshow-for-drupal-update/927#comments</comments>
		<pubDate>Fri, 24 Oct 2008 17:31:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[admin screen]]></category>

		<category><![CDATA[array]]></category>

		<category><![CDATA[be]]></category>

		<category><![CDATA[bugs]]></category>

		<category><![CDATA[change language]]></category>

		<category><![CDATA[copy paste]]></category>

		<category><![CDATA[demo]]></category>

		<category><![CDATA[downloads]]></category>

		<category><![CDATA[drupal]]></category>

		<category><![CDATA[email]]></category>

		<category><![CDATA[english]]></category>

		<category><![CDATA[features change]]></category>

		<category><![CDATA[footer]]></category>

		<category><![CDATA[fpss]]></category>

		<category><![CDATA[french text]]></category>

		<category><![CDATA[front]]></category>

		<category><![CDATA[front page slideshow]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[hook]]></category>

		<category><![CDATA[javascript library]]></category>

		<category><![CDATA[language text]]></category>

		<category><![CDATA[languages]]></category>

		<category><![CDATA[new features]]></category>

		<category><![CDATA[news]]></category>

		<category><![CDATA[openness]]></category>

		<category><![CDATA[page]]></category>

		<category><![CDATA[php file]]></category>

		<category><![CDATA[problem]]></category>

		<category><![CDATA[problems]]></category>

		<category><![CDATA[queue]]></category>

		<category><![CDATA[slideshow]]></category>

		<category><![CDATA[update]]></category>

		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=927</guid>
		<description><![CDATA[I have updated my Front Page Slideshow for Drupal module with some new features and some fixes.
New Features:

Change language text within DrupalWithin the admin screen of FPSS you can now add the language text for the slideshow within Drupal which is stored in variables.  By default the module has the English text in.  [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>I have updated my Front Page Slideshow for Drupal module with some new features and some fixes.</p>
<p><strong>New Features:</strong></p>
<ul>
<li>Change language text within Drupal<br />Within the admin screen of FPSS you can now add the language text for the slideshow within Drupal which is stored in variables.  By default the module has the English text in.  If you want the French text, then you will have to open up the french.php file and copy paste each item in to the form and save it.</li>
<li>Change javascript location<br />Within the admin screen as well as being able to turn off the javascript library and optimize the javascript you can now selected if you want the javascript to be inserted in to the footer of the page rather than the header.  This is tested and works on a default Drupal installation of 5.12.</li>
</ul>
<p><strong>Fixes</strong></p>
<ul>
<li>Optimize JS and Disable JS both work as expected now and any configuration of the 2 settings should work, although some javascript packages may conflict causing problems.</li>
<li>Fixed the admin settings access, missing array item in hook_perm.</li>
</ul>
<p>You can download the <a href="http://code.google.com/p/fpss-drupal/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');">fpss for drupal module</a> at the <a href="http://code.google.com/p/fpss-drupal/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');">Google Code</a> site and you can view the demo of the <a href="http://drupal.jamestombs.co.uk" >Front Page Slideshow for Drupal demo</a> at <a href="http://drupal.jamestombs.co.uk" >http://drupal.jamestombs.co.uk</a>.</p>
<p>If you have any problems or find any bugs please submit them on the <a href="http://code.google.com/p/fpss-drupal/issues/list" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');">FPSS for Drupal Issue Queue</a> on the Google Code site. Alternatively leave a comment to this post or email at jtombs1987@gmail.com.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-24/fpss-front-page-slideshow-for-drupal-update/927/feed</wfw:commentRss>
		</item>
		<item>
		<title>Spam from 93.174.93.89</title>
		<link>http://jamestombs.co.uk/2008-10-24/spam-from-931749389/925</link>
		<comments>http://jamestombs.co.uk/2008-10-24/spam-from-931749389/925#comments</comments>
		<pubDate>Fri, 24 Oct 2008 12:45:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PCs]]></category>

		<category><![CDATA[akismet]]></category>

		<category><![CDATA[be]]></category>

		<category><![CDATA[honey pot]]></category>

		<category><![CDATA[ipetitions]]></category>

		<category><![CDATA[ips]]></category>

		<category><![CDATA[pics]]></category>

		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=925</guid>
		<description><![CDATA[One of the sites I look after is getting a lot of spam from 93.174.93.89 with messages being posted like below:
comment2, http://www.ipetitions.com/petition/d34w79rvw Clitorus sex site,  fgx, http://www.ipetitions.com/petition/d34w254d5 Clitoris sex site,  :), http://www.ipetitions.com/petition/d34woxbl0 Clits major size sex,  02056, http://www.ipetitions.com/petit
and
comment4, http://www.ipetitions.com/petition/d34w76t2e Clothed sex movies free,  385, http://www.ipetitions.com/petition/d34w0mtv2 Clothed sex party,  :-((, http://www.ipetitions.com/petition/d34wv876u [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>One of the sites I look after is getting a lot of spam from 93.174.93.89 with messages being posted like below:<br />
<code>comment2, http://www.ipetitions.com/petition/d34w79rvw Clitorus sex site,  fgx, http://www.ipetitions.com/petition/d34w254d5 Clitoris sex site,  :), http://www.ipetitions.com/petition/d34woxbl0 Clits major size sex,  02056, http://www.ipetitions.com/petit</code></p>
<p>and<br />
<code>comment4, http://www.ipetitions.com/petition/d34w76t2e Clothed sex movies free,  385, http://www.ipetitions.com/petition/d34w0mtv2 Clothed sex party,  :-((, http://www.ipetitions.com/petition/d34wv876u Clothed sex pic free,  %P, http://www.ipetitions.com/</code></p>
<p>The site has both Akismet and Project Honey Pot protecting it and isn&#8217;t detected by either.</p>
<p>Add to the ban list.</p>
<p>Other IPs that have been spamming the site alot are:</p>
<p>78.110.175.15<br />
94.102.60.43<br />
94.102.60.77<br />
94.102.60.39</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-24/spam-from-931749389/925/feed</wfw:commentRss>
		</item>
		<item>
		<title>Some people shouldn&#8217;t drink alcohol</title>
		<link>http://jamestombs.co.uk/2008-10-23/some-people-shouldnt-drink-alcohol/922</link>
		<comments>http://jamestombs.co.uk/2008-10-23/some-people-shouldnt-drink-alcohol/922#comments</comments>
		<pubDate>Thu, 23 Oct 2008 18:28:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=922</guid>
		<description><![CDATA[Video shot from an in car camera from the police in USA. 

]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Video shot from an in car camera from the police in USA. </p>
<p><!-- Smart Youtube --><span class="youtube"><object type="application/x-shockwave-flash" width="425" height="355" data="http://www.youtube.com/v/Bd4_zINaC44&amp;rel=0&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0"><param name="movie" value="http://www.youtube.com/v/Bd4_zINaC44&amp;rel=0&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="transparent" /></object></span></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-23/some-people-shouldnt-drink-alcohol/922/feed</wfw:commentRss>
		</item>
		<item>
		<title>Ford Mondeo 2007+ Leaking Boot problem fixed</title>
		<link>http://jamestombs.co.uk/2008-10-19/ford-mondeo-2007-leaking-boot-problem-fixed/918</link>
		<comments>http://jamestombs.co.uk/2008-10-19/ford-mondeo-2007-leaking-boot-problem-fixed/918#comments</comments>
		<pubDate>Sun, 19 Oct 2008 16:24:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Cars]]></category>

		<category><![CDATA[boot problem]]></category>

		<category><![CDATA[boots]]></category>

		<category><![CDATA[catchment]]></category>

		<category><![CDATA[ford]]></category>

		<category><![CDATA[mk4]]></category>

		<category><![CDATA[mondeo]]></category>

		<category><![CDATA[mondeo 2007]]></category>

		<category><![CDATA[news]]></category>

		<category><![CDATA[problem]]></category>

		<category><![CDATA[problems]]></category>

		<category><![CDATA[rear windscreen]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=918</guid>
		<description><![CDATA[The ongoing problem of leaking boots on the MK4 Ford Mondeo has been successfully fixed by replacing the rear windscreen with the new style rear windscreen which has a rubber catchment around the edge which puts all the water that is held by the boot in to the area at the very top of the [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>The <a href="http://jamestombs.co.uk/2008-08-11/ford-mondeo-mk4-2007-–-onwards-leaking-boot-problem/563" >ongoing problem of leaking boots on the MK4 Ford Mondeo</a> has been successfully fixed by replacing the rear windscreen with the new style rear windscreen which has a rubber catchment around the edge which puts all the water that is held by the boot in to the area at the very top of the boot which then flows down the sides of the boot like it should do.</p>
<p><em>Please note this only affects the hatchbacks which were made before April 2008.</em></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-19/ford-mondeo-2007-leaking-boot-problem-fixed/918/feed</wfw:commentRss>
		</item>
		<item>
		<title>Frontpage Slideshow for Drupal</title>
		<link>http://jamestombs.co.uk/2008-10-16/frontpage-slideshow-for-drupal/913</link>
		<comments>http://jamestombs.co.uk/2008-10-16/frontpage-slideshow-for-drupal/913#comments</comments>
		<pubDate>Thu, 16 Oct 2008 15:33:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<category><![CDATA[buggy]]></category>

		<category><![CDATA[control]]></category>

		<category><![CDATA[default settings]]></category>

		<category><![CDATA[developers]]></category>

		<category><![CDATA[displayed]]></category>

		<category><![CDATA[downloads]]></category>

		<category><![CDATA[drupal]]></category>

		<category><![CDATA[edition]]></category>

		<category><![CDATA[fpss]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[how]]></category>

		<category><![CDATA[image]]></category>

		<category><![CDATA[images]]></category>

		<category><![CDATA[javascript engine]]></category>

		<category><![CDATA[joomlaworks]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[languages]]></category>

		<category><![CDATA[mootools]]></category>

		<category><![CDATA[news]]></category>

		<category><![CDATA[node]]></category>

		<category><![CDATA[node types]]></category>

		<category><![CDATA[product]]></category>

		<category><![CDATA[scripted]]></category>

		<category><![CDATA[scripts]]></category>

		<category><![CDATA[slides]]></category>

		<category><![CDATA[uploading]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=913</guid>
		<description><![CDATA[I have begun coding a module to allow the Frontpage Slideshow to be displayed within a block or a panel.
Frontpage slideshow is a script by Joomlaworks.
The module requires that the script is purchased from Joomlaworks as it contains important files for it to work.
The module which is currently in development can be found at http://code.google.com/p/fpss-drupal/.
The [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>I have begun coding a module to allow the Frontpage Slideshow to be displayed within a block or a panel.</p>
<p>Frontpage slideshow is a script by Joomlaworks.</p>
<p>The module requires that the script is purchased from Joomlaworks as it contains important files for it to work.</p>
<p>The module which is currently in development can be found at <a href="http://code.google.com/p/fpss-drupal/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');">http://code.google.com/p/fpss-drupal/</a>.</p>
<p>The code is still in an early stage but is working and usable, but I would recommend not using it on a production site.</p>
<p>There are a few issues with the module at the moment.</p>
<ul>
<li>Module depends on jquery_update</li>
<li>Module uses the upload module to upload the image for the slide, but this allows any file to be uploaded, so requires some further work.</li>
</ul>
<h2>How does it work</h2>
<p>The module adds in 2 new node types (slide, slideshow).  Each slideshow node creates a new block which can be used anywhere in your site.</p>
<p>Slides are then assigned to a slideshow.  The slideshow node contains most of the important settings such as dimensions and timings but as well as this there is an admin settings page which controls the default settings across the whole site such as the language of the text and the javascript engine.</p>
<p>I have developed the module purely with jQuery in mind.  Mootools may work, but is likely to be unstable and buggy.</p>
<h2>Where can I download this module?</h2>
<p>Go to <a href="http://code.google.com/p/fpss-drupal/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');">http://code.google.com/p/fpss-drupal/</a> and download it from the right hand side.  If you find any issues with the module please do so by leaving an issue on the Google Code site.</p>
<div class="amazon"><a href="http://www.amazon.co.uk/Pro-Drupal-Development-2nd/dp/1430209895%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1430209895" ><img src="http://ecx.images-amazon.com/images/I/51ygqAHbDkL._SL75_.jpg" /></a></div>
<h3>Useful Drupal Module Development Book</h3>
<p>Pro Drupal Development is a very good book published by Apress.  The new second edition covers Drupal 6.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-16/frontpage-slideshow-for-drupal/913/feed</wfw:commentRss>
		</item>
		<item>
		<title>[PHP + MySQL] Making a basic product database - Part 1</title>
		<link>http://jamestombs.co.uk/2008-10-12/php-mysql-making-a-basic-product-database-part-1/705</link>
		<comments>http://jamestombs.co.uk/2008-10-12/php-mysql-making-a-basic-product-database-part-1/705#comments</comments>
		<pubDate>Sun, 12 Oct 2008 18:29:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[apache php]]></category>

		<category><![CDATA[array]]></category>

		<category><![CDATA[auto increment]]></category>

		<category><![CDATA[automatic id]]></category>

		<category><![CDATA[base]]></category>

		<category><![CDATA[data]]></category>

		<category><![CDATA[database]]></category>

		<category><![CDATA[database management tool]]></category>

		<category><![CDATA[db name]]></category>

		<category><![CDATA[email]]></category>

		<category><![CDATA[fail]]></category>

		<category><![CDATA[host localhost]]></category>

		<category><![CDATA[localhost]]></category>

		<category><![CDATA[my news]]></category>

		<category><![CDATA[my query browser]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[phpmyadmin]]></category>

		<category><![CDATA[product]]></category>

		<category><![CDATA[roots]]></category>

		<category><![CDATA[servers]]></category>

		<category><![CDATA[sql]]></category>

		<category><![CDATA[statement]]></category>

		<category><![CDATA[strings]]></category>

		<category><![CDATA[test environment]]></category>

		<category><![CDATA[update]]></category>

		<category><![CDATA[varchar]]></category>

		<category><![CDATA[variables]]></category>

		<category><![CDATA[web folder]]></category>

		<category><![CDATA[web server]]></category>

		<category><![CDATA[windows]]></category>

		<category><![CDATA[xxxx]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=705</guid>
		<description><![CDATA[
Firstly you need a server which supports PHP and Mysql. If you haven&#8217;t got one, you can set up your computer as a local web server. If you are on Windows, you can follow this guide to help you Set up your PC as a test environment using Apache, PHP and MySQL.
Create the database and [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="amazon"><a href="http://www.amazon.co.uk/PHP-Easy-Steps-Colour/dp/184078282X%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D184078282X" ><img src="http://ecx.images-amazon.com/images/I/413WS8031EL._SL75_.jpg" /></a></div>
<p>Firstly you need a server which supports PHP and Mysql. If you haven&#8217;t got one, you can set up your computer as a local web server. If you are on Windows, you can follow this guide to help you <a href="http://jamestombs.co.uk/2008-09-22/set-up-your-pc-as-a-test-environment-using-apache-php-and-mysql/634" >Set up your PC as a test environment using Apache, PHP and MySQL</a>.</p>
<h2>Create the database and tables</h2>
<p>Open up your database management tool (PHPMyAdmin or command prompt or MySQL Query Browser) and create a new database, I will call mine product_db.</p>
<p>Then we want to create 3 tables. Product, companies and ownership.</p>
<p>The products table will contain 3 fields:</p>
<p>pid - A unique ID that is automatically generated for us.<br />
name - The name of the product.<br />
weight - The weight of the product.</p>
<p>This is the SQL for the table I am creating:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql mysql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE TABLE</span> products <span style="color: #66cc66;">&#40;</span>
pid <span style="color: #aa9933; font-weight: bold;">INT</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> <span style="color: #aa3399; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY KEY</span> ,
name <span style="color: #aa9933; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
weight <span style="color: #aa9933; font-weight: bold;">FLOAT</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Next up is the companies table which will contain 3 fields.</p>
<p>cid - A unique ID that is automatically generated for us.<br />
name - The name of the company.<br />
email - A contact email address for the company.</p>
<p>This is the SQL for the table I am creating:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql mysql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE TABLE</span> companies <span style="color: #66cc66;">&#40;</span>
cid <span style="color: #aa9933; font-weight: bold;">INT</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> <span style="color: #aa3399; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY KEY</span> ,
name <span style="color: #aa9933; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span> ,
email <span style="color: #aa9933; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The 3rd table is the ownership table which will link up products to companies.</p>
<p>This will contain 2 fields, pid and cid which relate to the automatic ID of the 2 other tables.</p>
<p>This is the SQL for the table I am creating:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql mysql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE TABLE</span> ownership <span style="color: #66cc66;">&#40;</span>
cid <span style="color: #aa9933; font-weight: bold;">INT</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span>,
pid <span style="color: #aa9933; font-weight: bold;">INT</span> <span style="color: #aa3399; font-weight: bold;">NOT NULL</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Now that we have the tables set up we can write the PHP to interact with the tables.</p>
<h2>Connecting to the database using PHP</h2>
<p>In your web folder, create a file and call it db_config.php.</p>
<p>In this file we will make the connection to the database.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$db_host</span> <span style="color: #339933;">=</span> <span style="">'localhost'</span>;
<span style="color: #000088;">$db_user</span> <span style="color: #339933;">=</span> <span style="">'root'</span>;
<span style="color: #000088;">$db_pass</span> <span style="color: #339933;">=</span> <span style="">'password'</span>;
<span style="color: #000088;">$db_name</span> <span style="color: #339933;">=</span> <span style="">'product_db'</span>;
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_host</span><span style="color: #339933;">,</span><span style="color: #000088;">$db_user</span><span style="color: #339933;">,</span><span style="color: #000088;">$db_pass</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_name</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Change the $db_xxxx variables to your database settings.</p>
<p>Save the file and load it up in your browser.  If you get a blank white screen, everything is OK.</p>
<h3>Possible Errors</h3>
<p>Some possible errors you may get are&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Unknown database 'product1_db'</pre></div></div>

<p>This will be because $db_name is wrong.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'loc1alhost' (11001) in D:\xampp\htdocs\product\db_config.php on line 3
Unknown MySQL server host 'loc1alhost' (11001)</pre></div></div>

<p>This is because the $db_host is wrong.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ro1ot'@'localhost' (using password: YES) in D:\xampp\htdocs\product\db_config.php on line 3
Access denied for user 'ro1ot'@'localhost' (using password: YES)</pre></div></div>

<p>This could be because $db_user is wrong or $db_pass is wrong.</p>
<h2>Inserting new products in to the database</h2>
<p>Create a new file and call it index.php and put it in the same location as the db_config.php file and paste the following code in it:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">require_once</span> <span style="">'db_config.php'</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Previewing the page should result in a blank white page. This means that everything is OK.</p>
<p>Now we will create a function which will used for all our modifying database interactions such as inserting data, updating data and deleting data.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="">'insert'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$keys</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: #000088;">$key</span>;
				<span style="color: #000088;">$values</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: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$keys</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) VALUES (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="">'update'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; SET &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="">'delete'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is set up for inserting data only at the moment, both update and delete would fail at the moment, unless the data was passed on properly.</p>
<p>To insert data into the database we will pass all the information the db_function needs in an array like the one below.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="">'insert'</span><span style="color: #339933;">,</span>
  <span style="">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="">'products'</span><span style="color: #339933;">,</span>
  <span style="">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Product Name'</span><span style="color: #339933;">,</span>
    <span style="">'weight'</span> <span style="color: #339933;">=&gt;</span> <span style="">'12.5'</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>By looking at the db_action function you can see that the action part of the array defines what we want to do in the database (insert, update or delete), then we have the table name (products, companies, ownership) and a data array which is in the format of the key (column name in the database) and the value we want to put in to the database.</p>
<p>We draw this data out the array in to a workable format using the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$keys</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: #000088;">$key</span>;
  <span style="color: #000088;">$values</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: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This goes through the data array within our main array and spits out the $keys and $values that we will use for the database.</p>
<p>Once we have the $keys and $values arrays we need to organise these in a way that MySQL will know to insert correctly.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This sets the arrays in to strings with each field separated with a comma.  Perfect for MySQL.</p>
<p>We then insert the data in to the database using the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$keys</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) VALUES (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>From the above array, the information sent to MySQL would be:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql mysql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> products <span style="color: #66cc66;">&#40;</span>name, weight<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Product Name'</span>, <span style="color: #ff0000;">'12.5'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h2>Inserting new companies in to the database</h2>
<p>By changing the array we can completely change the data that is going in to the database.  Now lets modify the array to insert a new company.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="">'insert'</span><span style="color: #339933;">,</span>
  <span style="">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="">'companies'</span><span style="color: #339933;">,</span>
  <span style="">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Something Enterprise'</span><span style="color: #339933;">,</span>
    <span style="">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="">'info@somethingenterprise.com'</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>So with the following code, by viewing the page we will insert data in to both tables.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">require_once</span> <span style="">'db_config.php'</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="">'action'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="">'action'</span><span style="color: #009900;">&#93;</span>;
<span style="color: #000088;">$pid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="">'pid'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="">'pid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="">'pid'</span><span style="color: #009900;">&#93;</span>;
<span style="color: #000088;">$cid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="">'cid'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="">'cid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="">'cid'</span><span style="color: #009900;">&#93;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="">'insert'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$keys</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: #000088;">$key</span>;
				<span style="color: #000088;">$values</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: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$keys</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) VALUES (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="">'update'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; SET &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="">'delete'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$product</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="">'insert'</span><span style="color: #339933;">,</span>
	<span style="">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="">'products'</span><span style="color: #339933;">,</span>
	<span style="">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Product Name'</span><span style="color: #339933;">,</span>
		<span style="">'weight'</span> <span style="color: #339933;">=&gt;</span> <span style="">'12.5'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000088;">$company</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="">'insert'</span><span style="color: #339933;">,</span>
	<span style="">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="">'companies'</span><span style="color: #339933;">,</span>
	<span style="">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Something Enterprise'</span><span style="color: #339933;">,</span>
		<span style="">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="">'info@somethingenterprise.com'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;
&nbsp;
db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span>;
db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$company</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Inserting new ownership in to the database</h2>
<p>Now that we have both a company and a product we can try linking them together. Although we will automate this later, check your database, both the product and company should have an ID of 1.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$ownership</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="">'insert'</span><span style="color: #339933;">,</span>
	<span style="">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="">'ownership'</span><span style="color: #339933;">,</span>
	<span style="">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="">'pid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
		<span style="">'cid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Then by running</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ownership</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>  We have the entry added to the ownership table.</p>
<h2>Updating existing data</h2>
<p>To update data we just need to modify our function a little to get the data in the right format and we can update with ease.</p>
<p>To do this we update the &#8216;update&#8217; case in our switch statement to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">case</span> <span style="">'update'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span><span style="">' = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="">'&quot;'</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="">' , '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'key'</span><span style="color: #009900;">&#93;</span>;
			<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'id'</span><span style="color: #009900;">&#93;</span>;
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; SET &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;</pre></div></div>

<p>We are using a similar foreach statement but have changed the 2 arrays into 1 array as the SQL format for UPDATE is different to INSERT.</p>
<p>For the update statement to work we need to pass on the values for the WHERE statement. After a minor change to our array we have the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$updateproduct</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="">'update'</span><span style="color: #339933;">,</span>
	<span style="">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="">'products'</span><span style="color: #339933;">,</span>
	<span style="">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="">'New Product Name'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="">'key'</span> <span style="color: #339933;">=&gt;</span> <span style="">'pid'</span><span style="color: #339933;">,</span>
	<span style="">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>We have changed the action and added 2 new array keys, 1 called key which is the column name that we will use in our SQL statement and the id which is the cid or pid that needs to be updated.</p>
<h2>Deleting data</h2>
<p>The DELETE case in our function is even easier than our UPDATE as we don&#8217;t need to much around with any data.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">case</span> <span style="">'delete'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'key'</span><span style="color: #009900;">&#93;</span>;
			<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'id'</span><span style="color: #009900;">&#93;</span>;
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #b1b100;">break</span>;</pre></div></div>

<p>Our DELETE array is almost identical to our UPDATE array.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$deleteproduct</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="">'delete'</span><span style="color: #339933;">,</span>
	<span style="">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="">'products'</span><span style="color: #339933;">,</span>
	<span style="">'key'</span> <span style="color: #339933;">=&gt;</span> <span style="">'pid'</span><span style="color: #339933;">,</span>
	<span style="">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>All we need is the key and id as no data is needed to delete a row.</p>
<p>In part 2 we will create the HTML to do our functions.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-12/php-mysql-making-a-basic-product-database-part-1/705/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
