title: Making replies to an existing comment system in Android
body: <p>So we have a comment system in our application, and now we want to be able to add replies to specific comments, like a Facebook wall.</p>
  
  <p>Our Java method for posting a comment:</p>
  
  <pre><code>class PostComment extends AsyncTask&lt;String, String, String&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(AddCommentActivity.this);
          pDialog.setMessage("Posting Comment...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();
      }
  
      @Override
      protected String doInBackground(String... args) {
          // TODO Auto-generated method stub
           // Check for success tag
          int success;
          String post_title = title.getText().toString();
          String post_message = message.getText().toString();
  
          //We need to change this:
          SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(AddCommentActivity.this);
          String post_username = sp.getString("username", "anon");
  
          try {
              // Building Parameters
              List&lt;NameValuePair&gt; params = new ArrayList&lt;&gt;();
              params.add(new BasicNameValuePair("username", post_username));
              params.add(new BasicNameValuePair("title", post_title));
              params.add(new BasicNameValuePair("message", post_message));
  
              Log.d("request!", "starting");
  
              //Posting user data to script 
              JSONObject json = jsonParser.makeHttpRequest(
                      POST_COMMENT_URL, "POST", params);
  
              // full json response
              Log.d("Post Comment attempt", json.toString());
  
              // json success element
              success = json.getInt(TAG_SUCCESS);
              if (success == 1) {
                  Log.d("Comment Added!", json.toString());    
                  finish();
                  return json.getString(TAG_MESSAGE);
              }else{
                  Log.d("Comment Failure!", json.getString(TAG_MESSAGE));
                  return json.getString(TAG_MESSAGE);
  
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return null;
  
      }
  
      protected void onPostExecute(String file_url) {
          // dismiss the dialog once product deleted
          pDialog.dismiss();
          if (file_url != null){
              Toast.makeText(AddCommentActivity.this, file_url, Toast.LENGTH_LONG).show();
          }
      }
  }
  }
  </code></pre>
  
  <p>and our PHP to send to MySQL:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  //load and connect to MySQL database stuff
  require("config.inc.php");
  $query_params=null;
  
  if (!empty($_POST)) {
      //initial query
      $query = "INSERT INTO comments ( username, title, message ) VALUES (   :user, :title, :message ) ";
  
       //Update query
      $query_params = array(
          ':user' =&gt; $_POST['username'],
          ':title' =&gt; $_POST['title'],
           ':message' =&gt; $_POST['message']
      );
  
      //execute query
      try {
          $stmt   = $db-&gt;prepare($query);
          $result = $stmt-&gt;execute($query_params);
      }
       catch (PDOException $ex) {
          // For testing, you could use a die and message. 
          //die("Failed to run query: " . $ex-&gt;getMessage());
  
         //or just use this use this one:
          $response["success"] = 0;
          $response["message"] = "Database Error. Couldn't add post!";
          die(json_encode($response));
      }
  
      $response["success"] = 1;
      $response["message"] = "Post Successfully Added!";
      //echo json_encode($response);
  
  } else {
  ?&gt;
  </code></pre>
  
  <p>I've made a new table in MySQL called replies which has:</p>
  
  <pre><code>reply_id (INT AI)
  reply_content (text)
  reply_postid (INT)
  reply_byusername (varchar)
  </code></pre>
  
  <p>I'm guessing somehow we make an <code>arraylist</code> that picks the <code>commentid</code> from the original comment and we can chain that to replies, but I don't know how. I generally have no idea how to proceed from here.</p>