Jump to content

jerastraub

Members
  • Posts

    77
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jerastraub's Achievements

Member

Member (2/5)

0

Reputation

  1. This worked great, but i can't find the topic solved button
  2. This is the way that I have always seen to do a DB connect. I have also seen that most people actually put it in a folder like so: <? include("inc/config.php"); ?>
  3. Anyone that can help me with this?
  4. much like the following: Items 11-20 of 100 displayed. 11 12 13 14 15 16 17 18 19 20 first prev [1-10][11-20][21-30][31-40][41-50][51-60][61-70][71-80][81-90][91-100] next last back to home page
  5. Hello, This is doing the pagination part ie.(<< 1 2) or (1 2 >>). I need it to also do "Displaying 1 to 9 (of 14 products)".
  6. I have a pagination script, i just need a tip on how to add "Displaying 1 to 9 (of 14 products)" any help would be great!
  7. 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!
  8. 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!
  9. I added mysql_query(" DELETE FROM example_temp WHERE ProductName='ProductName'") or die(mysql_error()); so i asked my own question, rofl
  10. Okay, one last question. How do I exclude the first row of the CVS when uploading, as these are the row titles? ie. ProductName MfgCode SKU UPC Category Brand Description Keywords Price MSRP OnSale IsNew InStock ProductURL SmallImageURL BigImageURL Shipping BulkPrice
  11. I don't see a solved button anywhere. I feel like a noob!
  12. Thanks guys, Here is the end result code that works perfectly: <? $dbh=mysql_connect ("localhost", "Username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("Database"); // File can be anywhere on the Internet $FeedFile = 'http://fssrv.com/api.aspx?req=3&fmt=2&adid=77&afid=1213797&fid=104&cid=-1&s=1&kt=1'; mysql_query("drop table example_temp"); mysql_query("CREATE TABLE example_temp ( ProductName varchar(100) NOT NULL, MfgCode varchar(100) NOT NULL, SKU varchar(50) NOT NULL, UPC varchar(50) NOT NULL, Category varchar(100) NOT NULL, SubCategory varchar(100) NOT NULL, Brand varchar(50) NOT NULL, Description blob NOT NULL, Keywords blob NOT NULL, Price varchar(7) NOT NULL default '0.00', MSRP varchar(7) NOT NULL default '0.00', IsNew varchar(50) NOT NULL, InStock varchar(50) NOT NULL, ProductURL varchar(100) NOT NULL, SmallImageURL varchar(250) NOT NULL, BigImageURL varchar(250) NOT NULL, Shipping varchar(100) NOT NULL, BulkPrice varchar(100) NOT NULL, BulkMinimum varchar(100) NOT NULL)") or die(mysql_error()); $feed = fopen($FeedFile, 'r'); $rowNum = 1; $recCount = 0; while ($data = fgetcsv ($feed, 3000, ",")) { $pieces = explode("/~", $data[4]); $pieces[0]; // piece1 $pieces[1]; // piece2 $pieces[2]; // piece3 $data[0] = str_replace("'", "‚", $data[0]); $data[1] = str_replace("'", "‚", $data[1]); $data[2] = str_replace("'", "‚", $data[2]); $data[3] = str_replace("'", "‚", $data[3]); $data[4] = str_replace("'", "‚", $data[4]); $data[5] = str_replace("'", "‚", $data[5]); $data[6] = str_replace("'", "‚", $data[6]); $data[7] = str_replace("'", "‚", $data[7]); $data[8] = str_replace("'", "‚", $data[8]); $data[9] = str_replace("'", "‚", $data[9]); $data[10] = str_replace("'", "‚", $data[10]); $data[11] = str_replace("'", "‚", $data[11]); $data[12] = str_replace("'", "‚", $data[12]); $data[13] = str_replace("'", "‚", $data[13]); $data[14] = str_replace("'", "‚", $data[14]); $data[15] = str_replace("'", "‚", $data[15]); $data[16] = str_replace("'", "‚", $data[16]); $data[17] = str_replace("'", "‚", $data[17]); $query = "insert into example_temp (`ProductName`, `MfgCode`, `SKU`, `UPC`, `Category`, `SubCategory`, `Brand`, `Description`, `Keywords`, `Price`, `MSRP`, `IsNew`, `InStock`, `ProductURL`, `SmallImageURL`, `BigImageURL`, `Shipping`, `BulkPrice`, `BulkMinimum`) VALUES('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."', '".$pieces[0]."', '".$pieces[2]."', '".$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]."')"; $result = mysql_query($query) or die("Invalid query: " . mysql_error()); $row++; } mysql_query("drop table example"); mysql_query("ALTER TABLE example_temp RENAME example") or die(mysql_error()); echo "Datafeed Import Completed Successfully"; $sql = "SELECT COUNT(*) FROM example"; $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."; } ?> Also I used ‚ as the replacement character rather than ", as I need the apostrophe to diplay in the merchant URLs and product names and descriptions. One last thing though, is there a way to shorten the piece of code and still get the same result : $data[0] = str_replace("'", "‚", $data[0]); $data[1] = str_replace("'", "‚", $data[1]); $data[2] = str_replace("'", "‚", $data[2]); $data[3] = str_replace("'", "‚", $data[3]); $data[4] = str_replace("'", "‚", $data[4]); $data[5] = str_replace("'", "‚", $data[5]); $data[6] = str_replace("'", "‚", $data[6]); $data[7] = str_replace("'", "‚", $data[7]); $data[8] = str_replace("'", "‚", $data[8]); $data[9] = str_replace("'", "‚", $data[9]); $data[10] = str_replace("'", "‚", $data[10]); $data[11] = str_replace("'", "‚", $data[11]); $data[12] = str_replace("'", "‚", $data[12]); $data[13] = str_replace("'", "‚", $data[13]); $data[14] = str_replace("'", "‚", $data[14]); $data[15] = str_replace("'", "‚", $data[15]); $data[16] = str_replace("'", "‚", $data[16]); $data[17] = str_replace("'", "‚", $data[17]); Thanks again guys!
  13. Okay, Don't pay attention to the last post. I finally got it to where it will insert values in to the temp database: <? $dbh=mysql_connect ("localhost", "Username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); // File can be anywhere on the Internet $FeedFile = 'http://fssrv.com/api.aspx?req=3&fmt=2&adid=77&afid=1213797&fid=104&cid=-1&s=1&kt=1'; mysql_query("drop table example_temp"); mysql_query("CREATE TABLE example_temp ( ProductName varchar(100) NOT NULL, MfgCode varchar(100) NOT NULL, SKU varchar(50) NOT NULL, UPC varchar(50) NOT NULL, Category varchar(100) NOT NULL, SubCategory varchar(100) NOT NULL, Brand varchar(50) NOT NULL, Description blob NOT NULL, Keywords blob NOT NULL, Price varchar(7) NOT NULL default '0.00', MSRP varchar(7) NOT NULL default '0.00', IsNew varchar(50) NOT NULL, InStock varchar(50) NOT NULL, ProductURL varchar(100) NOT NULL, SmallImageURL varchar(100) NOT NULL, BigImageURL varchar(100) NOT NULL, Shipping varchar(100) NOT NULL, BulkPrice varchar(100) NOT NULL, BulkMinimum varchar(100) NOT NULL)") or die(mysql_error()); $feed = fopen($FeedFile, 'r'); $rowNum = 1; $recCount = 0; while ($data = fgetcsv ($feed, 1000, ",")) { $pieces = explode("/~", $data[4]); $pieces[0]; // piece1 $pieces[1]; // piece2 $pieces[2]; // piece3 $query = "insert into example_temp (`ProductName`, `MfgCode`, `SKU`, `UPC`, `Category`, `SubCategory`, `Brand`, `Description`, `Keywords`, `Price`, `MSRP`, `IsNew`, `InStock`, `ProductURL`, `SmallImageURL`, `BigImageURL`, `Shipping`, `BulkPrice`, `BulkMinimum`) VALUES('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."', '".$pieces[0]."', '".$pieces[2]."', '".$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]."')"; $result = mysql_query($query) or die("Invalid query: " . mysql_error()); $row++; } mysql_query("drop table example"); mysql_query("ALTER TABLE example_temp RENAME example") or die(mysql_error()); ?> However I am now getting the follow error: Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's left wheel spacer and allows all maintenance jobs such as tire I'm getting closer, just not there yet!
  14. Here's my code so far: <? <? $dbh=mysql_connect ("localhost", "Username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("Database"); // File can be anywhere on the Internet $FeedFile = 'http://fssrv.com/api.aspx?req=3&fmt=2&adid=77&afid=1213797&fid=104&cid=-1&s=1&kt=1'; mysql_query("drop table example_temp"); mysql_query("CREATE TABLE example_temp ( PRIMARY KEY (MfgCode), ProductName varchar(100) NOT NULL, MfgCode varchar(100) NOT NULL, SKU varchar(50) NOT NULL, UPC varchar(50) NOT NULL, Category varchar(100) NOT NULL, SubCategory varchar(100) NOT NULL, Brand varchar(50) NOT NULL, Description blob NOT NULL, Keywords blob NOT NULL, Price varchar(7) NOT NULL default '0.00', MSRP varchar(7) NOT NULL default '0.00', IsNew varchar(50) NOT NULL, InStock varchar(50) NOT NULL, ProductURL varchar(100) NOT NULL, SmallImageURL varchar(100) NOT NULL, BigImageURL varchar(100) NOT NULL, Shipping varchar(100) NOT NULL, BulkPrice varchar(100) NOT NULL, BulkMinimum varchar(100) NOT NULL)") or die(mysql_error()); $feed = fopen($FeedFile, 'r'); $rowNum = 1; $recCount = 0; while($data = fgetcsv($feed, 3000, ',')){ if($rowNum > 0){ $iProductName = addslashes($data[0]); $iMfgCode = addslashes($data[1]); $iSKU = addslashes($data[2]); $iUPC = addslashes($data[3]); $iCategory = addslashes($data[4]); $iBrand = addslashes($data[5]); $iDescription = addslashes($data[6]); $iKeywords = addslashes($data[7]); $iPrice = addslashes($data[8]); $iMSRP = addslashes($data[9]); $iIsNew = addslashes($data[10]); $iInStock = addslashes($data[11]); $iProductURL = addslashes($data[12]); $iSmallImageURL = addslashes($data[13]); $iBigImageURL = addslashes($data[14]); $iShipping = addslashes($data[15]); $iBulkPrice = addslashes($data[16]); $iBulkMinimum = addslashes($data[17]); $pieces = explode(" ", $data[4]); $pieces[0]; // piece1 $pieces[1]; // piece2 $pieces[2]; // piece3 print_r ($data); $sql = mysql_query("insert into example_temp (ProductName, MfgCode, SKU, UPC, Category, SubCategory, Brand, Description, Keywords, Price, MSRP, IsNew, InStock, ProductURL, SmallImageURL, BigImageURL, Shipping, BulkPrice, BulkMinimum) values (''$iProductName', '$iMfgCode', '$iSKU', '$iUPC', '$pieces[0]', '$pieces[2]', '$iBrand', '$iDescription', '$iKeywords', '$iPrice', '$iMSRP', '$iIsNew', '$iInStock', '$iProductURL', '$iSmallImageURL', '$iBigImageURL', '$iShipping', '$iBulkPrice', '$iBulkMinimum' )") or die(mysql_error()); $recCount++; } $rowNum++; } mysql_query("drop table example"); mysql_query("ALTER TABLE example_temp RENAME example") or die(mysql_error()); ?> I don't understand where you are talking about putting: $sql = "INSERT INTO example_table..."; $result = mysql_query($sql) or die(mysql_error() . "/n<pre>$sql");
×
×
  • 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.