djdellux Posted December 3, 2008 Share Posted December 3, 2008 I need to make an interface/viewer program for an excel spread sheet. I can either use the sheet as is as I'm told or I can parsing it to a DB which I believe would be more efficient. can anyone tell me how I would go about doing that. mind you I'm searching the net all over but I wanted to ask the pros too.... Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/ Share on other sites More sharing options...
djdellux Posted December 3, 2008 Author Share Posted December 3, 2008 I have the file saved as a CSV file I just need to parse it btw. Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/#findComment-704939 Share on other sites More sharing options...
MatthewJ Posted December 3, 2008 Share Posted December 3, 2008 <?php $filetoimport = 'yourfile.csv'; $fp = fopen("$filetoimport", 'r'); if (!$fp) {echo 'ERROR: Unable to open file'; exit;} while (!feof($fp)) { $line = fgets($fp, 1024); // use 2048 if very long lines list ($field1, $field2, $field3) = split (",", $line); //Insert values to db $fp++; } fclose($fp); ?> You should be able to adapt that Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/#findComment-704950 Share on other sites More sharing options...
Mark Baker Posted December 3, 2008 Share Posted December 3, 2008 I need to make an interface/viewer program for an excel spread sheet.If you need to work with an actual Excel workbook rather than CSV, then I'd recommend PHPExcel Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/#findComment-704988 Share on other sites More sharing options...
djdellux Posted December 3, 2008 Author Share Posted December 3, 2008 I came up with this do you fellas see any probs with it??? <?php $columns = "`c1` , `c2`, `c3`,`c4`, `c5`, `c6` , `c7`, `c8`, `c9`, `c10` , `c11`, `c12`, `c13`, `c14` , `c15`, `c16` "; $handle = fopen("main.csv", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { foreach( $data as $v ) { $insertValues="'".addslashes(trim($v))."'"; } $values=implode(',',$insertValues); $sql = "INSERT INTO `tableName` ( $columns ) VALUES ( $values )"; mysql_query($sql) or die('SQL ERROR:'.mysql_error()); } fclose($handle); ?> Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/#findComment-705001 Share on other sites More sharing options...
djdellux Posted December 3, 2008 Author Share Posted December 3, 2008 are any of you aware of a function *file* that will get an array as apposed to *fgets* Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/#findComment-705062 Share on other sites More sharing options...
djdellux Posted December 3, 2008 Author Share Posted December 3, 2008 this is my code... i am recieveing this error Warning: implode() [function.implode]: Argument to implode must be an array. in c:\program files\Apache\htdocs\csv.php on line 9 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in c:\program files\Apache\htdocs\csv.php on line 11 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in c:\program files\Apache\htdocs\csv.php on line 11 SQL ERROR:Access denied for user 'ODBC'@'localhost' (using password: NO) going to lunch ill see if yall can help when i return thx in advance gents <?php $columns = "`c1` , `c2`, `c3`,`c4`, `c5`, `c6` , `c7`, `c8`, `c9`, `c10` , `c11`, `c12`, `c13`, `c14` , `c15`, `c16`c17` "; $handle = fopen("master.csv", "r"); $data = fgetcsv($handle, 2048, ","); foreach( $data as $v ) { $insertValues="'".addslashes(trim($v))."'"; } $values=implode(',',$insertValues); $sql = "INSERT INTO `VoIP` ( $columns ) VALUES ( $values )"; mysql_query($sql) or die('SQL ERROR:'.mysql_error()); fclose($handle); $db = $_SERVER['DOCUMENT_ROOT']."/../data/master.db"; //connect to MYsql $handle = mysql_select_db($db); $query = "SELECT * FROM log WHERE "; $conditions = array(); ?> Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/#findComment-705089 Share on other sites More sharing options...
djdellux Posted December 3, 2008 Author Share Posted December 3, 2008 intresting...... ??? Link to comment https://forums.phpfreaks.com/topic/135343-new-project-assistance-needed/#findComment-705140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.