0

i want to post from Android to a CSV File correctly. Now the php posts the Question, Answer and the User in one column. With \n i can switch to a new row in the CSV File. \t doesn't work.

Now it look like this:

Column1

Question1Answer1User1

Question2Answer2User2 ...

It should view like this:

Column1| Column2| Column3

Question1| Answer1 | User1

Question2| Answer2 | User2

..

The Java Code inside the Android App.

 protected String doInBackground(String... args) {
 List<NameValuePair> params = new ArrayList<NameValuePair>();
 for (int i = 0; i < dbHandler.getAllStimmungen().size(); i++) {
 params.add(new BasicNameValuePair("question"+i, dbHandler.getAllStimmungen().get(i).getQuestion()));
 params.add(new BasicNameValuePair("answer"+i, dbHandler.getAllStimmungen().get(i).getAnswer()));
 params.add(new BasicNameValuePair("user"+i, httpHandler.getContact(1).getuserName()+"\n"));
 }
 JSONObject json = jsonParser.makeHttpRequest(url_create_product,
 "POST", params);
 return null;
 }

The PHP Code

<?php
 $timestamp = date("d.m.y-H:i:s"); 
 $filename= 'myTextFile-'.$timestamp.'.csv';
 $lastIndex = 0;
 // receive data from app's http request
 $data=($_POST);
 // write data from my android app to a text file
 file_put_contents($filename,$data);
 ?>

Sorry for my English!

asked Nov 26, 2013 at 14:09

1 Answer 1

0

CSV stands for Comma Separated Value. It means that columns are separated by commas. Said that, a new line character \n switches to a new row and has nothing to do with columns. You have to put commas between every single value in the csv file.

column1,column2,column3, \n
value1,value2,value3, \n
value11, value22, value33,
answered Nov 26, 2013 at 14:26
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.