Retrieving Rating from Database and Setting of RatingBar on Android
<p>I've been trying to tackle this problem for quite some time now. I'm actually trying to get the user's rating on a particular place from the database, and then pass it back to android. On android, according to the retrieve information from the database, then set the rating appropriately on the RatingBar. Below are my segments of code:</p>

<pre><code>ArrayList&lt;NameValuePair&gt; post_Parameters = new ArrayList&lt;NameValuePair&gt;();
    post_Parameters.add(new BasicNameValuePair("pID", placeID.toString()));
    post_Parameters.add(new BasicNameValuePair("username", FootprintSession.getUsername().toString()));

    String response2 = null;

    try{

        response2 = (CustomHttpClient.executeHttpPost("http://test.com/getUserRating.php", post_Parameters)).toString();

        if(response.isEmpty())
        {
              //trying to print out what is the response
            Toast.makeText(getBaseContext(), "response"+response2, Toast.LENGTH_LONG).show();
            userRatingBar.setRating(defaultRating);
        }
        else
        {
            Toast.makeText(getBaseContext(), "Found : "+response2, Toast.LENGTH_LONG).show();
            userRating = (float)(Double.parseDouble(response2));
            userRatingBar.setRating(userRating);
        }

    }catch(Exception e){
        Log.e("Error in Rating",""+e);
    }
</code></pre>

<p>this is the part on my PHP:</p>

<pre><code>&lt;?php

$un = $_POST['username'];
$pID = $_POST['pID'];

$mysql_host = "localhost";
$mysql_database = "testDB";
$mysql_user = "testAdmin";
$mysql_password = "**********";

//connect to the database
$conn = mysql_connect($mysql_host, $mysql_user, $mysql_password);

mysql_select_db($mysql_database, $conn);

$query = "SELECT rating FROM fpRating WHERE username = '$un' AND placeID = '$pID' ";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());

if(mysql_num_rows($result) == 0) {
    echo null;
}else
{
    $row = mysql_fetch_assoc($result)
    echo $row["rating"];
}
</code></pre>

<p>?></p>

<p>**
My rating on my database is a double type.</p>

<p>My logcat prints:
java.lang.NumberFormatException
**</p>
