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!
1 Answer 1
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,