Jump to content

datafeed upload


Recommended Posts

Okay here is my code:

 

<?
            
		// Connecting to the database

		 $dbh=mysql_connect ("localhost", "usernname", "password") 
            or die ('I cannot connect to the database because: ' . mysql_error()); 
            mysql_select_db ("database"); 
        
                  // File can be anywhere on the Internet
             $FeedFile = 'feed.csv';
         
	 // Creating Temporary table in the database
	        
          mysql_query("drop table example_temp");
                  mysql_query("CREATE TABLE example_temp (
          ProductID varchar(100) NOT NULL,
	  Name varchar(250) NOT NULL,
	  Description blob NOT NULL,  
	  Thumbnail varchar(250) NOT NULL,
	  BigImage varchar(250) NOT NULL, 
	  Price varchar(7) NOT NULL default '0.00',
	  PayOptionText varchar(250) NOT NULL,
	  Shipping varchar(250) NOT NULL,
	  SpecialShippingText varchar(250) NOT NULL,
	  ShippingTime varchar(250) NOT NULL,
	  Guarantee blob NOT NULL,
	  Disclaimer blob NOT NULL,
	  CallNumber varchar(250) NOT NULL,
	  CategoryID varchar(250) NOT NULL,
	  Category2 varchar(250) NOT NULL,
	  Trademark varchar(250) NOT NULL,
	  DateLastEdited varchar(250) NOT NULL,
	  CSRPhone varchar(250) NOT NULL,
	  OrderTypeID varchar(250) NOT NULL,
	  Type varchar(250) NOT NULL,
	  AffAv varchar(250) NOT NULL,
	  Video blob NOT NULL,
	  CheckByPhoneYN varchar(250) NOT NULL)") or die(mysql_error());
                
			// Opening the Feed

                  $feed = fopen($FeedFile, 'are'); 	// subtract the a and the e from are. As the forum is spellchecking the code and changing it to the for "are".  
                  $rowNum = 1;
                  $recCount = 0;
                
                  while ($data = fgetcsv ($feed, 3000, ",")) {


// Inserting the feed values into  Temporary database
			  
$query = "insert into example_temp (`ProductID`,`Name`,`Description`,`Thumbnail`,`BigImage`,`Price`,`PayOptionText`,`Shipping`,`SpecialShippingText`,`ShippingTime`,`Guarantee`,`Disclaimer`,`CallNumber`,`CategoryID`,`Category2`,`Trademark`,`DateLastEdited`,`CSRPhone`,`OrderTypeID`,`Type`,`AffAv`,`Video`,`CheckByPhoneYN`) 
VALUES
('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."', '".$data[4]."', '".$data[5]."', '".$data[6]."', '".$data[7]."', '".$data[8]."', '".$data[9]."', '".$data[10]."', '".$data[11]."', '".$data[12]."', '".$data[13]."', '".$data[14]."', '".$data[15]."', '".$data[16]."', '".$data[17]."', '".$data[18]."', '".$data[19]."', '".$data[20]."', '".$data[21]."')";
    $result = mysql_query($query) or die("Invalid query: " . mysql_error());
    $row++;
}
          
	  
// Dropping Main Table and Replace Temporary Table to replace the Main table

                mysql_query("drop table something");
           mysql_query("ALTER TABLE example_temp RENAME some") or die(mysql_error());
              
		  // Anouncing feed import success  
             
		 echo "Datafeed Import Completed Successfully"; 

//counting records in the new table and showing the amount in the browser window		 

$sql = "SELECT COUNT(*) FROM something";
       $result = mysql_query($sql);
if($result)
{
  $row = mysql_fetch_row($result);
  $count = $row[0];
  echo "<br />";
   echo "There are ";
   echo $count;
   echo " records in the database.";

} 
else
{
  echo "no result from database.";
}


?> 

 

It works fine for files that come in cvs format. However I have some file that are provided in .xls format only.  I know I have to change something in the following line:

while ($data = fgetcsv ($feed, 3000, ",")) 

, but I have tried several things to no avail. Can I get a hand with what i need to change to get this to work for .xls and txt(tab delimited) formats.

 

Any help would be greatly appreciated!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.