jackgoddy123 Posted July 20, 2014 Share Posted July 20, 2014 Hi all, I am going through a very critical situation where I cannot find bright ideas to work upon. 1. I have an google spread sheet which contains few rows and columns. 2. I want to combine the row together including its column value.(1 row with four columns which results to a single sentence) 3. Simultaneously each row should form a single sentence from the google spread sheet. My spread sheet path: https://docs.google.com/spreadsheets/d/1Z7_oRxlTIiKIND89sAXHbyTsz1mrTMNwejqkfk8y5P0/edit#gid=0 I dont know how to strt of with this and which function, code to prefer ? Any kind of help is appreaciated. Quote Link to comment https://forums.phpfreaks.com/topic/290098-get-only-first-coulmn-to-concat-with-each-second-column-rows-from-csv-file-using-php/ Share on other sites More sharing options...
chriscloyd Posted July 20, 2014 Share Posted July 20, 2014 Google is a good way to find out information. I googled accessing Google spread sheet and found this. http://sim.plified.com/2008/09/14/accessing-google-spreadsheet-with-php/ Quote Link to comment https://forums.phpfreaks.com/topic/290098-get-only-first-coulmn-to-concat-with-each-second-column-rows-from-csv-file-using-php/#findComment-1485772 Share on other sites More sharing options...
chriscloyd Posted July 20, 2014 Share Posted July 20, 2014 http://www.farinspace.com/saving-form-data-to-google-spreadsheets/ that other one is outdated Quote Link to comment https://forums.phpfreaks.com/topic/290098-get-only-first-coulmn-to-concat-with-each-second-column-rows-from-csv-file-using-php/#findComment-1485773 Share on other sites More sharing options...
jackgoddy123 Posted July 24, 2014 Author Share Posted July 24, 2014 Hello all, Below is the code which I have tried so far and returns the output which I wanted. <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; echo "No files...!!!!!"; echo "<script>alert('No files...!!!!!');window.location.href='upload_file.php';</script>"; } else { $a=$_FILES["file"]["tmp_name"]; $csv_file = $a; if (($getfile = fopen($csv_file, "r")) !== FALSE) { $data = fgetcsv($getfile, 1000, ","); while (($data = fgetcsv($getfile, 1000, ",")) !== FALSE) { //$num = count($data); //echo $num; //for ($c=0; $c < $num; $c++) { $result = $data; $str = implode(",", $result); $slice = explode(",", $str); $col1 = $slice[0]; $col2 = $slice[1]; $col3 = $slice[2]; echo $col1."".$col2."".$col3."<br/>"; } } } ?> But now the case is that the files are been uploaded from .csv file. I want the fetch data from directly "google spread sheet" URL. In the baove code what will be the logic to add the spread sheet URl ? any help is appreciated. Thankyou...!! Quote Link to comment https://forums.phpfreaks.com/topic/290098-get-only-first-coulmn-to-concat-with-each-second-column-rows-from-csv-file-using-php/#findComment-1486080 Share on other sites More sharing options...
Ch0cu3r Posted July 24, 2014 Share Posted July 24, 2014 (edited) fgetcsv() returns the current rows data in an array for you, so there is then no need for any of this code $result = $data; $str = implode(",", $result); $slice = explode(",", $str); You'd concatenate $data[0] and $data[1] to join the first two columns together if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; echo "No files...!!!!!"; echo "<script>alert('No files...!!!!!');window.location.href='upload_file.php';</script>"; } else { $csv_file = $_FILES["file"]["tmp_name"]; if (($getfile = fopen($csv_file, "r")) !== FALSE) { $data = fgetcsv($getfile, 1000, ","); // this will ignore the first row - which is usually the column headings while (($data = fgetcsv($getfile, 1000, ",")) !== FALSE) { $col_1_and_2 = $data[0] . $data[1]; // concatenate column 1 and 2 echo $col_1_and_2 . '<br />'; // output the concatenated string } } } Edited July 24, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/290098-get-only-first-coulmn-to-concat-with-each-second-column-rows-from-csv-file-using-php/#findComment-1486087 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.