<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments for Tips and Tricks</title>
	<atom:link href="http://www.legend.ws/blog/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.legend.ws/blog</link>
	<description>Random tech ramblings</description>
	<lastBuildDate>Wed, 01 Feb 2012 19:11:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on PHP script to import csv data into mysql by Baldguy</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40566</link>
		<dc:creator>Baldguy</dc:creator>
		<pubDate>Wed, 01 Feb 2012 19:11:22 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40566</guid>
		<description>Thanks! I made a few tweaks, this works perfectly for me.</description>
		<content:encoded><![CDATA[<p>Thanks! I made a few tweaks, this works perfectly for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Microsoft Office Picture Manager takes a lot of time to load by Pete in CO</title>
		<link>http://www.legend.ws/blog/tips-tricks/slow-loading-microsoft-office-picture-manager/#comment-40417</link>
		<dc:creator>Pete in CO</dc:creator>
		<pubDate>Sat, 28 Jan 2012 22:51:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.legend.ws/blog/tips-tricks/slow-loading-microsoft-office-picture-manager/#comment-40417</guid>
		<description>Worked like a champ, thank you!!</description>
		<content:encoded><![CDATA[<p>Worked like a champ, thank you!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP script to import csv data into mysql by Hank</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40338</link>
		<dc:creator>Hank</dc:creator>
		<pubDate>Thu, 26 Jan 2012 23:31:25 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40338</guid>
		<description>I need to write a script to do the following.
1. read data from csv files in a bunch of directories (the list of directories will grow in time)
2. the idea is that these csv files will be updated by car dealers and then uploaded to their respective directories thru ftp (I&#039;m good with this bit as I will set the dir&#039;s and access)
3. problem comes in that at the dealer side the content of the files will keep changing. (some car info will remain / some will be deleted / and new ones will be added), this goes for all the dealers.
4. With every csv file they will upload images relating to the data in the csv files, so I will need to link this as well somehow.
5. the idea is to run this file with cron.php at set intervals to update the database (will ask how to do this when I get there)

What I&#039;ve managed so far is to loop through the lot with the glob function, and adding the files, but my problem is updating the database. (cars removed from the csv files must not be deleted just set to sold, so we can keep that data for statistics)

Hope someone can point me in the right direction.

This is the code i&#039;ve written so far:
PS: there are no headings in the csv files.

&lt;?php
$username =&quot;root&quot;;
$password = &quot;myPasword&quot;;
$host = &quot;localhost&quot;;
$table = &quot;csv_table&quot;;
$conn = new mysqli(&quot;$host&quot;, &quot;$username&quot;, &quot;$password&quot;);

// echo &quot;Connected to localhost&quot; . &quot;&quot;;

mysql_select_db(&quot;csvdb&quot;) or die(mysql_error());
// echo &quot;Connected to Database&quot;;

?&gt;


&lt;?php

// Set variable for csv file path 
$dir = &quot;dealer_upload/*/*.csv&quot;; 

// Open a known directory, and proceed to read its contents 
foreach(glob($dir) as $file) 
{ 
//echo &quot;PATH AND FILENAME: &quot; . $file . &quot;&quot;;

// Create the array

$fileTemp = $file;
$fp = fopen($fileTemp,&#039;r&#039;);
$datas = array();
while (($data = fgetcsv($fp)) !== FALSE)
{
$stockNumber = trim($data[0]);
$make = trim($data[1]);
$model = trim($data[2]);
$derivative = trim($data[3]);
$series = trim($data[4]);
$reg = trim($data[5]);
$vin = trim($data[6]);
$driveAwayPrice = trim($data[7]);
$priceExcluding = trim($data[8]);
$specialPrice = trim($data[9]);
$year = trim($data[10]);
$kilometres = trim($data[11]);
$body = trim($data[12]);
$colour = trim($data[13]);
$engine = trim($data[14]);
$transmission = trim($data[15]);
$fuel = trim($data[16]);
$options = trim($data[17]);
$sellingPoints = trim($data[18]);
$nvic = trim($data[19]);
$redBook = trim($data[20]);

// Insert Data
mysql_query (&quot;INSERT INTO $table (id_dealer, stockNumber, make, model, derivative, series, reg, vin, driveAwayPrice, priceExcluding, specialPrice, year, kilometres, body, colour, engine, transmission, fuel, options, sellingPoints, nvic, redBook)
VALUES (&#039;$file&#039;, &#039;$stockNumber&#039;, &#039;$make&#039;, &#039;$model&#039;, &#039;$derivative&#039;, &#039;$series&#039;, &#039;$reg&#039;, &#039;$vin&#039;, &#039;$driveAwayPrice&#039;, &#039;$priceExcluding&#039; ,&#039;$specialPrice&#039; , &#039;$year&#039; , &#039;$kilometres&#039; , &#039;$body&#039;, &#039;$colour&#039;, &#039;$engine&#039;, &#039;$transmission&#039;, &#039;$fuel&#039;, &#039;$options&#039;, &#039;$sellingPoints&#039;, &#039;$nvic&#039;, &#039;$redBook&#039;)
&quot;)
or die (mysql_error());


} 

} 

?&gt;</description>
		<content:encoded><![CDATA[<p>I need to write a script to do the following.<br />
1. read data from csv files in a bunch of directories (the list of directories will grow in time)<br />
2. the idea is that these csv files will be updated by car dealers and then uploaded to their respective directories thru ftp (I&#8217;m good with this bit as I will set the dir&#8217;s and access)<br />
3. problem comes in that at the dealer side the content of the files will keep changing. (some car info will remain / some will be deleted / and new ones will be added), this goes for all the dealers.<br />
4. With every csv file they will upload images relating to the data in the csv files, so I will need to link this as well somehow.<br />
5. the idea is to run this file with cron.php at set intervals to update the database (will ask how to do this when I get there)</p>
<p>What I&#8217;ve managed so far is to loop through the lot with the glob function, and adding the files, but my problem is updating the database. (cars removed from the csv files must not be deleted just set to sold, so we can keep that data for statistics)</p>
<p>Hope someone can point me in the right direction.</p>
<p>This is the code i&#8217;ve written so far:<br />
PS: there are no headings in the csv files.</p>
<p>&lt;?php<br />
$username =&quot;root&quot;;<br />
$password = &quot;myPasword&quot;;<br />
$host = &quot;localhost&quot;;<br />
$table = &quot;csv_table&quot;;<br />
$conn = new mysqli(&quot;$host&quot;, &quot;$username&quot;, &quot;$password&quot;);</p>
<p>// echo &quot;Connected to localhost&quot; . &quot;&#8221;;</p>
<p>mysql_select_db(&#8220;csvdb&#8221;) or die(mysql_error());<br />
// echo &#8220;Connected to Database&#8221;;</p>
<p>?&gt;</p>
<p>&lt;?php</p>
<p>// Set variable for csv file path<br />
$dir = &quot;dealer_upload/*/*.csv&quot;; </p>
<p>// Open a known directory, and proceed to read its contents<br />
foreach(glob($dir) as $file)<br />
{<br />
//echo &quot;PATH AND FILENAME: &quot; . $file . &quot;&#8221;;</p>
<p>// Create the array</p>
<p>$fileTemp = $file;<br />
$fp = fopen($fileTemp,&#8217;r');<br />
$datas = array();<br />
while (($data = fgetcsv($fp)) !== FALSE)<br />
{<br />
$stockNumber = trim($data[0]);<br />
$make = trim($data[1]);<br />
$model = trim($data[2]);<br />
$derivative = trim($data[3]);<br />
$series = trim($data[4]);<br />
$reg = trim($data[5]);<br />
$vin = trim($data[6]);<br />
$driveAwayPrice = trim($data[7]);<br />
$priceExcluding = trim($data[8]);<br />
$specialPrice = trim($data[9]);<br />
$year = trim($data[10]);<br />
$kilometres = trim($data[11]);<br />
$body = trim($data[12]);<br />
$colour = trim($data[13]);<br />
$engine = trim($data[14]);<br />
$transmission = trim($data[15]);<br />
$fuel = trim($data[16]);<br />
$options = trim($data[17]);<br />
$sellingPoints = trim($data[18]);<br />
$nvic = trim($data[19]);<br />
$redBook = trim($data[20]);</p>
<p>// Insert Data<br />
mysql_query (&#8220;INSERT INTO $table (id_dealer, stockNumber, make, model, derivative, series, reg, vin, driveAwayPrice, priceExcluding, specialPrice, year, kilometres, body, colour, engine, transmission, fuel, options, sellingPoints, nvic, redBook)<br />
VALUES (&#8216;$file&#8217;, &#8216;$stockNumber&#8217;, &#8216;$make&#8217;, &#8216;$model&#8217;, &#8216;$derivative&#8217;, &#8216;$series&#8217;, &#8216;$reg&#8217;, &#8216;$vin&#8217;, &#8216;$driveAwayPrice&#8217;, &#8216;$priceExcluding&#8217; ,&#8217;$specialPrice&#8217; , &#8216;$year&#8217; , &#8216;$kilometres&#8217; , &#8216;$body&#8217;, &#8216;$colour&#8217;, &#8216;$engine&#8217;, &#8216;$transmission&#8217;, &#8216;$fuel&#8217;, &#8216;$options&#8217;, &#8216;$sellingPoints&#8217;, &#8216;$nvic&#8217;, &#8216;$redBook&#8217;)<br />
&#8220;)<br />
or die (mysql_error());</p>
<p>} </p>
<p>} </p>
<p>?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getting rid of the ^M characters in vi by Prosthetic lips &#124; Findcds</title>
		<link>http://www.legend.ws/blog/linux/removing-the-m-character-in-vim/#comment-40300</link>
		<dc:creator>Prosthetic lips &#124; Findcds</dc:creator>
		<pubDate>Thu, 26 Jan 2012 01:17:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.legend.ws/blog/?p=29#comment-40300</guid>
		<description>[...] Tips and Tricks &#187; Blog Archive &#187; Getting rid of the ^M characters in viJan 1, 2009 &#8230; Prosthetic LipsJanuary 21st, 2011 at 10:26 PM. Um &#8230; just a note, your explanation of the $ is wrong. 1,$ means &#8220;lines 1 through the end of the &#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] Tips and Tricks &#187; Blog Archive &#187; Getting rid of the ^M characters in viJan 1, 2009 &#8230; Prosthetic LipsJanuary 21st, 2011 at 10:26 PM. Um &#8230; just a note, your explanation of the $ is wrong. 1,$ means &#8220;lines 1 through the end of the &#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP script to import csv data into mysql by Laura</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40192</link>
		<dc:creator>Laura</dc:creator>
		<pubDate>Mon, 23 Jan 2012 16:57:47 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40192</guid>
		<description>Hi this code is great and easy to use, however I think I am doing something wrong:

I have a .csv that includes numbers and url&#039;s ect ...the only row that your code will import into my sql is the first row which is just text as it is titles. I have taken that row out of the .cvs but the code is still not pulling the imformation - therefore I know that it is not a case of the code only pulling the 1st row ...it is what is in the .csv rows... L

Someone please help me because I am completely stuck! :-(</description>
		<content:encoded><![CDATA[<p>Hi this code is great and easy to use, however I think I am doing something wrong:</p>
<p>I have a .csv that includes numbers and url&#8217;s ect &#8230;the only row that your code will import into my sql is the first row which is just text as it is titles. I have taken that row out of the .cvs but the code is still not pulling the imformation &#8211; therefore I know that it is not a case of the code only pulling the 1st row &#8230;it is what is in the .csv rows&#8230; L</p>
<p>Someone please help me because I am completely stuck! <img src='http://www.legend.ws/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP script to import csv data into mysql by passerby</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40036</link>
		<dc:creator>passerby</dc:creator>
		<pubDate>Fri, 20 Jan 2012 03:37:30 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-40036</guid>
		<description>thanks. the code provided really saving my time :)</description>
		<content:encoded><![CDATA[<p>thanks. the code provided really saving my time <img src='http://www.legend.ws/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Getting rid of the ^M characters in vi by LTC</title>
		<link>http://www.legend.ws/blog/linux/removing-the-m-character-in-vim/#comment-39270</link>
		<dc:creator>LTC</dc:creator>
		<pubDate>Fri, 06 Jan 2012 10:40:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.legend.ws/blog/?p=29#comment-39270</guid>
		<description>s means &quot;substitute&quot; not &quot;search and replace&quot;.  And it isn&#039;t nonsense. 
Searching, of course, is achieved using with the forward slash / character.</description>
		<content:encoded><![CDATA[<p>s means &#8220;substitute&#8221; not &#8220;search and replace&#8221;.  And it isn&#8217;t nonsense.<br />
Searching, of course, is achieved using with the forward slash / character.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP script to import csv data into mysql by Stefan</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-38937</link>
		<dc:creator>Stefan</dc:creator>
		<pubDate>Fri, 30 Dec 2011 08:18:04 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-38937</guid>
		<description>Hy
The script is fine, working great, but i need an advice
My table has 3 colomns: 
id, code and name
I allready have some data inserted, and i want to insert only the info that&#039;s mesing.
I need to check only by cod. So if the code exists , the scipt shold not inserted.

Thanks in advance for advices.

Best Regards,
Stefan</description>
		<content:encoded><![CDATA[<p>Hy<br />
The script is fine, working great, but i need an advice<br />
My table has 3 colomns:<br />
id, code and name<br />
I allready have some data inserted, and i want to insert only the info that&#8217;s mesing.<br />
I need to check only by cod. So if the code exists , the scipt shold not inserted.</p>
<p>Thanks in advance for advices.</p>
<p>Best Regards,<br />
Stefan</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP script to import csv data into mysql by Rolf</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-38008</link>
		<dc:creator>Rolf</dc:creator>
		<pubDate>Thu, 08 Dec 2011 17:05:32 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-38008</guid>
		<description>It&#039;s not such a good script... how to deal with a few thousends or more records? 
It aint nice to the database to run thousends of queries when you could do a much better import by storing maybe 1000 lines in 1 import..</description>
		<content:encoded><![CDATA[<p>It&#8217;s not such a good script&#8230; how to deal with a few thousends or more records?<br />
It aint nice to the database to run thousends of queries when you could do a much better import by storing maybe 1000 lines in 1 import..</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP script to import csv data into mysql by Ankur</title>
		<link>http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-37932</link>
		<dc:creator>Ankur</dc:creator>
		<pubDate>Wed, 07 Dec 2011 16:35:01 +0000</pubDate>
		<guid isPermaLink="false">http://legend.ws/blog/tips-tricks/csv-php-mysql-import/#comment-37932</guid>
		<description>Hi guys,

Please help me in this script. It only inserts 240 records in database.</description>
		<content:encoded><![CDATA[<p>Hi guys,</p>
<p>Please help me in this script. It only inserts 240 records in database.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

