<?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>ineedtutorials.com &#187; advanced</title>
	<atom:link href="http://www.ineedtutorials.com/tag/advanced/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ineedtutorials.com</link>
	<description>Information made easy</description>
	<lastBuildDate>Thu, 14 May 2009 15:17:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>9 PHP Debugging Techniques You Should Be Using</title>
		<link>http://www.ineedtutorials.com/code/php/9-php-debugging-techniques-you-should-be-using</link>
		<comments>http://www.ineedtutorials.com/code/php/9-php-debugging-techniques-you-should-be-using#comments</comments>
		<pubDate>Tue, 12 May 2009 10:33:58 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[debugging]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/?p=256</guid>
		<description><![CDATA[Isn&#8217;t writing new code great? Wouldn&#8217;t the world be a better place if all were ever had to do is write software from scratch, not having to worry about methods of classes past? Unfortunately, we all know that this is not the case. In fact, estimates say that we spend around 80% of our programming [...]]]></description>
			<content:encoded><![CDATA[<p>Isn&#8217;t writing new code great? Wouldn&#8217;t the world be a better place if all were ever had to do is write software from scratch, not having to worry about methods of classes past? Unfortunately, we all know that this is not the case. In fact, estimates say that we spend around 80% of our programming time maintaining old code.<br />
<span id="more-256"></span><br />
<strong>The tutorial talks about following techniques:</strong></p>
<ul>
<li>Enable Notices (on your development environment!)</li>
<li>Use a Logging System</li>
<li>Log Errors</li>
<li>Check Function Parameters</li>
<li>Use an Integrated Development Environment and Debugger</li>
<li>Unit Testing</li>
<li>No Magic! (Or, Avoid Side Effects)</li>
<li>Use Manual Redirects When Debugging</li>
<li>Keep Things Simple</li>
</ul>
<p>Link: <a href="http://porteightyeight.com/archives/151-9-PHP-Debugging-Techniques-You-Should-Be-Using.html">9 PHP Debugging Techniques You Should Be Using</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/9-php-debugging-techniques-you-should-be-using/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Started with Memcache</title>
		<link>http://www.ineedtutorials.com/code/php/getting-started-with-memcache</link>
		<comments>http://www.ineedtutorials.com/code/php/getting-started-with-memcache#comments</comments>
		<pubDate>Tue, 12 May 2009 10:15:30 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[Memcache]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/?p=249</guid>
		<description><![CDATA[Memcache is a tool which can cache objects in memory – and is often used for speeding up dynamic web applications. PHP has a built-in module for working with memcache, and its a simple and convenient way of introducing caching to your application. PHP has a PECL module for talking to memcached – look up [...]]]></description>
			<content:encoded><![CDATA[<p>Memcache is a tool which can cache objects in memory – and is often used for speeding up dynamic web applications. PHP has a built-in module for working with memcache, and its a simple and convenient way of introducing caching to your application.</p>
<p>PHP has a PECL module for talking to memcached – look up how to install for your system, but be aware that it isn’t bundled. It’s a good module to include on your system however, quite a few apps will take advantage of it where available.<br />
<span id="more-249"></span><br />
Memcache is object storage, objects are stored in a serialised manner in RAM, with a unique key to identify them. This means that you need a unique string to identify any object you may store in the cache. Primary keys work fine but look out for when you are storing multiple types of object in there &#8211; <object_type>_
<primary_key> probably works better in that scenario.</p>
<p>The storage persists as long as the machine is on – a reboot empties the RAM and therefore clears the cache. You can also set how long a cached object is valid for. After that time, memcache will return false when you request your object and your code will fall through to its usual retrieval process.</p>
<p>Link: <a href="http://techportal.ibuildings.com/2009/02/16/getting-started-with-memcached/">Getting Started with Memcache</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/getting-started-with-memcache/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC, XSLT and other animals</title>
		<link>http://www.ineedtutorials.com/code/php/mvc-xslt-and-other-animals</link>
		<comments>http://www.ineedtutorials.com/code/php/mvc-xslt-and-other-animals#comments</comments>
		<pubDate>Tue, 12 May 2009 10:09:48 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[architectural pattern]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/?p=247</guid>
		<description><![CDATA[The MVC architectural pattern is a smart and bright way of developing web-based applications. The acronym MVC stands for Model, View and Control: these are the three components that, according to the pattern, every application can (and should) be divided into. I would actually state that MVC is &#8220;the ultimate&#8221; way of developing apps but [...]]]></description>
			<content:encoded><![CDATA[<p>The MVC architectural pattern is a smart and bright way of developing web-based applications. The acronym MVC stands for Model, View and Control: these are the three components that, according to the pattern, every application can (and should) be divided into. I would actually state that MVC is &#8220;the ultimate&#8221; way of developing apps but since IT is such a fast-growing/evolving discipline, I won&#8217;t dare being so bold and just say that it is certainly a topic every good developer should spend some time on.<br />
<span id="more-247"></span><br />
This article will try to briefly expose the basics of the MVC pattern and put forward an alternative template management system based on the duo XML/XSLT. Many MVC implementations in php are actually quite fuzzy in the way they manage the Views layer. Most of them partially fail in separating the markup from the programming language and there are often some residual bits of php code here and there.</p>
<p>As he&#8217;ll show you in a while, it is absolutely possible (and wise) to keep the two things clearly distinct and obtain a complete separation of presentation from logic.</p>
<p>The goal of MVC pattern is, as stated above, to identify (divide and develop separately) the 3 layers we have briefly outlined. </p>
<p>Link: <a href="http://www.nourdine.net/index.php?action=article&#038;id=10">MVC, XSLT and other animals</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/mvc-xslt-and-other-animals/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Use PHP To Dynamically Resize an Image</title>
		<link>http://www.ineedtutorials.com/code/php/how-to-use-php-to-dynamically-resize-an-image</link>
		<comments>http://www.ineedtutorials.com/code/php/how-to-use-php-to-dynamically-resize-an-image#comments</comments>
		<pubDate>Mon, 11 May 2009 18:53:14 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[image manipulation]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/?p=245</guid>
		<description><![CDATA[One of the most annoying things about working with images is getting them into the right size. Screenshots start out huge &#8211; and you need to resize them to an appropriate size for your website. Some blogs automatically resize the pictures for you into a thumbnail &#8211; like the image to the right. What if [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most annoying things about working with images is getting them into the right size. Screenshots start out huge &#8211; and you need to resize them to an appropriate size for your website.</p>
<p>Some blogs automatically resize the pictures for you into a thumbnail &#8211; like the image to the right. What if you want the image a different size, though? You could allow the browser to resize it for you, or &#8211; better yet &#8211; write your own php script to resize the image dynamically.<br />
<span id="more-245"></span><br />
If we write our own php script to resize the image dynamically, we can control both the image size and the file size. Check out the third image to the right &#8211; which was resized with a php script. You’ll notice that it looks nicer too &#8211; the browser isn’t designed to resize images</p>
<p>Link: <a href="http://www.earn-web-cash.com/2008/01/30/resize-images-php/">How to Use PHP To Dynamically Resize an Image</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/how-to-use-php-to-dynamically-resize-an-image/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Windows Login (Active Directory) For your PHP applications</title>
		<link>http://www.ineedtutorials.com/code/php/use-windows-login-active-directory-for-your-php-applications</link>
		<comments>http://www.ineedtutorials.com/code/php/use-windows-login-active-directory-for-your-php-applications#comments</comments>
		<pubDate>Tue, 21 Apr 2009 10:17:35 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/?p=226</guid>
		<description><![CDATA[As a developer you may run into a situation such as what I had, numerous applications deployed. With multiple logins for all the apps, we had to find way to integrate all logins for better management and maintenance. Since we were using Apache with a PHP server, the solution was to find a way to [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer you may run into a situation such as what I had, numerous applications deployed.</p>
<p>With multiple logins for all the apps, we had to find way to integrate all logins for better management and maintenance.</p>
<p>Since we were using Apache with a PHP server, the solution was to find a way to consolidate the logins using PHP.<br />
<span id="more-226"></span><br />
The answer is ldap() (Lightweight Directory Access Protocol), this built in function through PHP, allows you to create username and password schemes using existing Windows authentication.</p>
<p>Link: <a href="http://hubpages.com/hub/Use-Windows-Login-in-PHP-Applications">Use Windows Login (Active Directory) For your PHP applications</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/use-windows-login-active-directory-for-your-php-applications/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework: Getting Started Screencasts</title>
		<link>http://www.ineedtutorials.com/code/php/zend-framework-getting-started-screencasts</link>
		<comments>http://www.ineedtutorials.com/code/php/zend-framework-getting-started-screencasts#comments</comments>
		<pubDate>Tue, 03 Feb 2009 18:38:57 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[PHP framework]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdesign]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/?p=168</guid>
		<description><![CDATA[Zend Framework is an open source, object-oriented web application framework implemented in PHP 5 and licensed under the New BSD License. Zend Framework—often referred to as ZF—is developed with the goal of simplifying web development while promoting best practices in the PHP developer community. Zend Framework was conceived in early 2005 while many new frameworks, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Zend Framework</strong> is an open source, object-oriented web application framework implemented in PHP 5 and licensed under the New BSD License. Zend Framework—often referred to as <strong>ZF</strong>—is developed with the goal of simplifying web development while promoting best practices in the PHP developer community.<span id="more-168"></span></p>
<p>Zend Framework was conceived in early 2005 while many new frameworks, such as Ruby on Rails and the Spring Framework, were gaining popularity in the web development community. ZF was publicly announced at the first Zend Conference.At the same time, no widely used framework had been made available to  the PHP community to fulfill similar web development needs. The  designers of Zend Framework sought to combine the ease-of-use and rapid application development (RAD) features of these new frameworks with the simplicity, openness,  and real-world practicality that is highly valued in the PHP community.</p>
<p>Typically, specific development usage scenarios are implemented using more generalized software components through automatic configuration and/or code generation.  In previous releases, the Zend Framework community has opted to  complete development and testing of these underlying components before  starting work on simplifying development tasks such as database  migrations, generating scaffolding,  and project creation and configuration. This practice has been the  subject of some criticism since some functionality considered by many  as necessary for a general release for modern web application frameworks is slated for future Zend Framework releases. Many ZF users, however,  have found such generalized software components more reusable and  extensible in implementing their applications. Zend Framework also  seeks to promote web development best practices in the PHP community; conventions are not as commonly used in ZF as in  many other frameworks, rather suggestions are put forth by setting  reasonable defaults that can be overridden for each ZF application’s  specific requirements.</p>
<p>Here is a set of screencasts designed to introduce a new user to the Zend Framework. They go over installation of the zend framework through creating a basic content website.</p>
<p>Link:  <a href="http://mitchellhashimoto.com/zend-framework-tutorials/getting-started/">Zend Framework: Getting Started Screencasts</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/zend-framework-getting-started-screencasts/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cutenews export to mysql &#8211; php tutorial</title>
		<link>http://www.ineedtutorials.com/code/php/cutenews-export-to-mysql-php-tutorial</link>
		<comments>http://www.ineedtutorials.com/code/php/cutenews-export-to-mysql-php-tutorial#comments</comments>
		<pubDate>Sat, 08 Dec 2007 14:16:48 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[cutenews]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/articles/cutenews-export-to-mysql-php-tutorial</guid>
		<description><![CDATA[Want to export your cutenews posts to a mysql database? In this tutorial i will show you how to export your posts from cutenews into a mysql table. Fist off we start by creating the connection to the database: $host: this is the location for the Mysql server it can be a hostname or an [...]]]></description>
			<content:encoded><![CDATA[<p>Want to export your cutenews posts to a mysql database? In this tutorial i will show you how to export your posts from cutenews into a mysql table.<br />
      <span id="more-13"></span></p>
<h3>Fist off we start by creating the connection to the database:</h3>
<ul>
<li>$host: this is the location for the Mysql server it can be a hostname or an ip adress. it is usualy localhost. </li>
<li>$db: this is the Mysql user account used to access the database. </li>
<li>$user: this is the password for the Mysql user account</li>
<li>$pass: this is the name of the Mysql database used. </li>
</ul>
<h3>Now we include the export function.</h3>
<p>We will need to include the function &#8216;cuteExport&#8217; in the file &#8216;cutenewsexport.php&#8217;</p>
<h3>Now we declare what data files should be exported from cutenews:</h3>
<ul>
<li>$newsfile: Cutenews uses &#8216;news.txt&#8217; for it&#8217;s data. Specify the FULL path to this file.</li>
<li>$categoryfile: Cutenews uses &#8216;category.db.php&#8217; for it&#8217;s categories. Specify the FULL path to this file.</li>
</ul>
<h3>Now we start the export to mysql by calling the function &#8216;cuteExport&#8217;:</h3>
<p>This function will export all data in the &#8216;news.txt&#8217; file and &#8216;category.db.php&#8217; and import it in a Mysql table.<br />
The function will export all data to a table called &#8216;cutenews_export_year_month_day_hour_min_sec&#8217; by default.<br />
You can change this in the cutenewsexport file where it says &#8216;$table = &#8220;cutenews_export_&#8221; . date(&#8220;Y_m_d_h_i_s&#8221;);&#8217;.<br />
When the function finishes all your data will be inserted into a mysql table.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p13code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p134"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p13code4"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// MYSQL database host adress</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// MYSQL database name</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Mysql Datbase user</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Mysql Datbase password</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Connect to the database</span>
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'cutenewsexport.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$newsfile</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">'news.txt'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$categoryfile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'category.db.php'</span><span style="color: #339933;">;</span>
&nbsp;
cuteExport<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newsfile</span><span style="color: #339933;">,</span><span style="color: #000088;">$categoryfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>The include file:</h3>
<p>Feel free to alter this file to your needs:</p>
<p>To change the default table name change the $table variable to your likings.</p>
<p>You can also export categories to a mysql table and use the ID as a reference in the export table.</p>
<p><em>file: cutenewsexport.php</em></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p13code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p135"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
</pre></td><td class="code" id="p13code5"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">############ DO NOT ALTER ############################
</span><span style="color: #000000; font-weight: bold;">function</span> str_replace_all<span style="color: #009900;">&#40;</span><span style="color: #000088;">$search</span><span style="color: #339933;">,</span> <span style="color: #000088;">$replace</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search</span><span style="color: #339933;">,</span> <span style="color: #000088;">$replace</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">############ END DO NOT ALTER ############################
</span>
<span style="color: #000000; font-weight: bold;">function</span> cuteExport<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newsfile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$categoryfile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newsfile</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Please specify a 'news.txt' file to export.&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$categoryfile</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Please specify a 'category.db.php' file to export.&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$export_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$export_success</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$export_failed</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$cat_count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$cat_success</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$cat_failed</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// table name</span>
    <span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;cutenews_export_&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y_m_d_h_i_s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tablecat</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;cutenews_export_cat_&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y_m_d_h_i_s&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// table sql</span>
    <span style="color: #000088;">$create</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
		CREATE TABLE  <span style="color: #006699; font-weight: bold;">$table</span> (
  			`id` int NOT NULL auto_increment,
 			`date` varchar(20) NOT NULL,
 			`author` text NOT NULL,
 		 	`title` text NOT NULL,
  			`short` text NOT NULL,
  			`full` text NOT NULL,
  			`categoryid` int NOT NULL,
  			PRIMARY KEY  (`id`)
		);&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$createcat</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
		CREATE TABLE  <span style="color: #006699; font-weight: bold;">$tablecat</span> (
  			`id` int NOT NULL auto_increment,
 			`category` varchar(100) NOT NULL,
  			PRIMARY KEY  (`id`)
		);&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$create</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Could not create export table !&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$createcat</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Could not create category table !&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$lines_cat</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$categoryfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines_cat</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$single_line_cat</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$cat_count</span><span style="color: #339933;">++;</span>
        <span style="color: #000088;">$value_arr_cat</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;|&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$single_line_cat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
        <span style="color: #000088;">$catsql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;insert into <span style="color: #006699; font-weight: bold;">$tablecat</span> (id,category) value ('<span style="color: #006699; font-weight: bold;">$value_arr_cat[0]</span>','<span style="color: #006699; font-weight: bold;">$value_arr_cat[1]</span>')&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catsql</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$catsql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$cat_success</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$cat_failed</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">// begin export</span>
    <span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newsfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$single_line</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$export_count</span><span style="color: #339933;">++;</span>
        <span style="color: #000088;">$value_arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;|&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$single_line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// insert export row in mysql table</span>
        <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$table</span> (date, author, title, short, full,categoryid) VALUES (
			 '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value_arr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</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: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value_arr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;',
			 '&quot;</span> <span style="color: #339933;">.</span> str_replace_all<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{nl}&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value_arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' ,
			 '&quot;</span> <span style="color: #339933;">.</span> str_replace_all<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{nl}&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value_arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;' ,
			 '&quot;</span> <span style="color: #339933;">.</span> str_replace_all<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;{nl}&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value_arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;4&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;',
			 '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value_arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;');&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// line exported</span>
            <span style="color: #000088;">$export_success</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//line export failed</span>
            <span style="color: #000088;">$export_failed</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">//Display export results</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;table border='0' cellpadding='5' cellspacing='1'&gt;
  			&lt;tr&gt;
    			&lt;td colspan='2'&gt;&lt;b&gt;Export finished:&lt;/b&gt;&lt;hr size='1' noshade&gt;&lt;/td&gt;
  			&lt;/tr&gt;
  			&lt;tr&gt;
  			  &lt;td align='center'&gt;<span style="color: #006699; font-weight: bold;">$export_count</span>&lt;/td&gt;
   			  &lt;td&gt;posts in total.&lt;/td&gt;
  			&lt;/tr&gt;
  			&lt;tr&gt;
    		  &lt;td align='center'&gt;<span style="color: #006699; font-weight: bold;">$export_success</span>&lt;/td&gt;
    		  &lt;td&gt;posts exported succesfuly.&lt;/td&gt;
  			&lt;/tr&gt;
  			&lt;tr&gt;
    		  &lt;td align='center'&gt;<span style="color: #006699; font-weight: bold;">$export_failed</span>&lt;/td&gt;
    		  &lt;td&gt;posts failed.&lt;/td&gt;
  			&lt;/tr&gt;
  			&lt;tr&gt;
  			  &lt;td colspan='2'&gt;&lt;hr size='1' noshade&gt;&lt;/td&gt;
   			  &lt;/tr&gt;
  				&lt;tr&gt;
  			  &lt;td align='center'&gt;<span style="color: #006699; font-weight: bold;">$cat_count</span>&lt;/td&gt;
   			  &lt;td&gt;categories in total.&lt;/td&gt;
  			&lt;/tr&gt;
  			&lt;tr&gt;
    		  &lt;td align='center'&gt;<span style="color: #006699; font-weight: bold;">$cat_success</span>&lt;/td&gt;
    		  &lt;td&gt;categories exported succesfuly.&lt;/td&gt;
  			&lt;/tr&gt;
  			&lt;tr&gt;
    		  &lt;td align='center'&gt;<span style="color: #006699; font-weight: bold;">$cat_failed</span>&lt;/td&gt;
    		  &lt;td&gt;categories failed.&lt;/td&gt;
  			&lt;/tr&gt;
		  &lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Displaying news on pages divided in category can be done by filtering your result per category per page:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p13code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p136"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" id="p13code6"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// MYSQL database host adress</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// MYSQL database name</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Mysql Datbase user</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Mysql Datbase password</span>
&nbsp;
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'cutenews_export_2007_12_13_10_13_15'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$categoryid</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// You should make this more secure...</span>
&nbsp;
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from <span style="color: #006699; font-weight: bold;">$table</span> where categoryid = '<span style="color: #006699; font-weight: bold;">$categoryid</span>' order by date &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// displaying the actual page results:</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><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>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;div id ='news_<span style="color: #006699; font-weight: bold;">$row[id]</span>'&gt;
&lt;h1&gt;<span style="color: #006699; font-weight: bold;">$row[title]</span> @ &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;l jS M Y @ g:ia&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/h1&gt;
&lt;div&gt;<span style="color: #006699; font-weight: bold;">$row[short]</span>&lt;/div&gt;
&lt;div&gt;<span style="color: #006699; font-weight: bold;">$row[full]</span>&lt;/div&gt;
&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now you can easily display news per category using a URL like: news.php?category=some_category_id</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/cutenews-export-to-mysql-php-tutorial/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
	</channel>
</rss>
