Jump to content

New Project Assistance Needed


djdellux

Recommended Posts

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

<?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

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);
?>

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();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.