<?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; export</title>
	<atom:link href="http://www.ineedtutorials.com/tag/export/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>Export Mysql data to CSV &#8211; PHP tutorial</title>
		<link>http://www.ineedtutorials.com/code/php/export-mysql-data-to-csv-php-tutorial</link>
		<comments>http://www.ineedtutorials.com/code/php/export-mysql-data-to-csv-php-tutorial#comments</comments>
		<pubDate>Sun, 16 Dec 2007 15:40:03 +0000</pubDate>
		<dc:creator>Gertjan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[csv export]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql export]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.ineedtutorials.com/articles/export-mysql-data-to-csv-php-tutorial</guid>
		<description><![CDATA[Want to export your Mysql data to a CSV(comma seperated value) file? In this tutorial i will show you how to export your data from Mysql into a CSV file. Fist off we start by creating the connection to the Mysql database: $host: this is the location for the Mysql server it can be a [...]]]></description>
			<content:encoded><![CDATA[<p>Want to export your Mysql data to a CSV(comma seperated value) file? In this tutorial i will show you how to export your data from Mysql into a CSV file. </p>
<p><span id="more-17"></span></p>
<h3>Fist off we start by creating the connection to the Mysql 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 ‘exportMysqlToCsv‘ in the file ‘exportcsv.inc.php‘</p>
<h3>Now we declare what table should be exported from Mysql into the CSV file: </h3>
<ul>
<li>$table: The name of the table that should be exported from Mysql to csv.</li>
</ul>
<h3>Now we start the export to csv from mysql by calling the function ‘exportMysqlToCsv‘: </h3>
<p>This function will export all data in the Mysql table. It will place the fieldnames on the first row of the CSV file. <br />
  The function will export all Mysql data to a file called ‘export.csv&#8217; by default. <br />
You can change this by adding an extra parameter to the exportMysqlToCsv: exportMysqlToCsv($tablename,$filename). <br />
  When the export finishes all your data will be inserted into the csv file and the file will be presented as a download. </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('p17code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p173"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p17code3"><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;">'exportcsv.inc.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$table</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this is the tablename that you want to export to csv from mysql.</span>
&nbsp;
exportMysqlToCsv<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</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 actual Mysql Export to csv function: </h3>
<p>Feel free to alter this file to your needs: </p>
<p>To change the default filename of the exported data change the $filename variable to your likings. </p>
<p>file: exportcsv.inc.php </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('p17code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p174"><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
</pre></td><td class="code" id="p17code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> exportMysqlToCsv<span style="color: #009900;">&#40;</span><span style="color: #000088;">$table</span><span style="color: #339933;">,</span><span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'export.csv'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$csv_terminated</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$csv_separator</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$csv_enclosed</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$csv_escaped</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$sql_query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from <span style="color: #006699; font-weight: bold;">$table</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Gets the data from the database</span>
    <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_query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$fields_cnt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_num_fields</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000088;">$schema_insert</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$fields_cnt</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$l</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$csv_enclosed</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_enclosed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$csv_escaped</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$csv_enclosed</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$csv_enclosed</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$schema_insert</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$l</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$schema_insert</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$csv_separator</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end for</span>
&nbsp;
    <span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$schema_insert</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$csv_terminated</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Format the data</span>
    <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>
        <span style="color: #000088;">$schema_insert</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$fields_cnt</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">++</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;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'0'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_enclosed</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: #000088;">$schema_insert</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</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;">$schema_insert</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$csv_enclosed</span> <span style="color: #339933;">.</span> 
					<span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_enclosed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$csv_escaped</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$csv_enclosed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$csv_enclosed</span><span style="color: #339933;">;</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>
                <span style="color: #000088;">$schema_insert</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">''</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: #000088;">$j</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$fields_cnt</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$schema_insert</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$csv_separator</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;">// end for</span>
&nbsp;
        <span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$schema_insert</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$csv_terminated</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end while</span>
&nbsp;
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: must-revalidate, post-check=0, pre-check=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Length: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$out</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Output to browser with appropriate mime type, you choose ;)</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/x-csv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//header(&quot;Content-type: text/csv&quot;);</span>
    <span style="color: #666666; font-style: italic;">//header(&quot;Content-type: application/csv&quot;);</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #006699; font-weight: bold;">$filename</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ineedtutorials.com/code/php/export-mysql-data-to-csv-php-tutorial/feed</wfw:commentRss>
		<slash:comments>103</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('p13code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138"><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="p13code8"><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('p13code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p139"><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="p13code9"><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('p13code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1310"><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="p13code10"><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>
