SetToLoki Posted October 20, 2007 Share Posted October 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74056-php-mysql-excel/ Share on other sites More sharing options...
dingus Posted October 20, 2007 Share Posted October 20, 2007 first thing that spring to mind would be to export to a txt file with , between fields then read in one line at a time (file()) and use explode to brake it to an array or you could use this function here http://sourceforge.net/projects/phpexcelreader/ Quote Link to comment https://forums.phpfreaks.com/topic/74056-php-mysql-excel/#findComment-373887 Share on other sites More sharing options...
harristweed Posted October 20, 2007 Share Posted October 20, 2007 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]; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74056-php-mysql-excel/#findComment-373897 Share on other sites More sharing options...
SetToLoki Posted October 20, 2007 Author Share Posted October 20, 2007 Thanks for the replies guys. I won't hit solved just yet till I make something that works, and will post my final code along with the solved button when it is done. Quote Link to comment https://forums.phpfreaks.com/topic/74056-php-mysql-excel/#findComment-373974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.