Jump to content

Recommended Posts

ok here is the problem

 

I am creating a php/mysql system to run daily chores. That is simple enough.

The hard part is the data that populates the database is sent each week via excel spreadsheet (always in the same format - thouhg row numbers change - coloms don't) I want to get this information using php and put the stuff I need from it in the database. Now I have found Navicat which is a great application and did what I needed only I am looking not to use a 3rd party program I simply want a button on the site that wil let you upload a spreadsheet and fill the database correcting any info in the databse allready that is reppeated etc as I won't be the one doing this and for most the users of this post things like navicat are simple enough for the people using the sytem I am creating that is a bit too much like hard work even with all the training.

 

So my question is can this be done and where should I start I pretty much to the point where I realise I will need to open the excel file and stick all the information into an array and then take it from the array and insert into databse. But how do I do this. some links to usefull info or some sample code would help I am quite quick to pick this stuff up when I get on to the right trail.

 

Thanks TJ.

Link to comment
https://forums.phpfreaks.com/topic/74056-php-mysql-excel/
Share on other sites

Export from excel as a csv file.

Upload the csv file to your server

Read the file and update the database as necessary

This is how you read the file

<?php
$filename = "your_file.csv";
$handle = fopen($filename, "rb");
$data = fread($handle, filesize($filename));
//each row will be in array called $data
$rows=explode("\r", $data);
$count=count($rows);
for ($i=0;$i<$count;$i++)
{
//set $number_columns= columns in spread sheet
$sub_data=explode(",", $rows[$i]);
for($x=0;$x<=$number_columns;$x++)
{
	// update datbase here
//data in column one = $sub_data[$x];
//data in column two = $sub_data[$x];
//data in column three = $sub_data[$x];
}

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/74056-php-mysql-excel/#findComment-373897
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.