I am able to present the organizations for a user selected city and state and I am then able to "down select" using the id which presents me with the json encoded data for a single organization. The problem is that along with the json encoded data I am getting the table headings along with the grid. This means that when I try to grab the json data with an HttpResponse I get a "java.lang.StringIndexOutOfBoundsException" since I am essentially reading all of the HTML contained in the citystate.php file as well as the json data. Here is the code that works but presents the problem as just described. How do I retunr just the json data?

<html> 
<head> 
<title>Locate Organizations Form</title> 
<h3 style="background-color:#33990f"<FONT COLOR="#FFFAFA">Organizations</FONT></h3> 
</head>
<body style="background-color:#33990f"> 

<?php 

show_organizations();
select_oneorg();

function show_organizations() {

// connect include
require ("connect.php");
$query = "SELECT orgname, org_id FROM organizations WHERE ";    
    if (strlen($_GET['orgcity']) > 0)	    
             $query .= " organizations.orgcity LIKE '%{$_GET['orgcity']}%' AND ";
$query .= "organizations.orgstate = '{$_GET['orgstate']}'";
/* Temporary ECHO of the $sql string */ 
/* echo $query; */
//
// ensure you have retrieved results of query
//
$result = mysql_query($query)or die(mysql_error());
    if (!$result) { 
      echo("<p>Error performing query: " . mysql_error() . "</p>"); 
      exit(); 
    } 

?>
<div>
<table border="1" cellspacing="2" cellpadding="2" style="background-color:#33990f;border-width:2px;width:100%;">
<tr>
<th><font face="Arial, Helvetica, sans-serif";font color="#FFFAFA">Organization Name</font></th>
<th><font face="Arial, Helvetica, sans-serif";font color="#FFFAFA">ID</font></th>
</tr>

<?php
//
// put results into table
//
    while ($row = mysql_fetch_assoc($result))
    {
        echo("<tr>\n<td>" . $row["orgname"] . "</td>"); 
        echo "<td>";
        echo "<a href = '?varID=".$row['org_id']."'>".$row['org_id']."</td></a>";  
    }
}
?>
</table>
</div>
<?php

function select_oneorg() {

if (isset($_GET['varID'])){
    $query = "SELECT * FROM organizations WHERE org_id = {$_GET['varID']}";

    /* Temporary ECHO of the $sql string */ 
    /* echo $query; */
    $result = mysql_query($query)or die(mysql_error());
    if (!$result) { 
      echo("<p>Error performing query: " . mysql_error() . "</p>"); 
      exit(); 
    } 
    while ($row = mysql_fetch_assoc($result))
    {
	    echo(json_encode($row));
    }
}
}
/* Closes Connection to MySQL server */ 
mysql_close(); 
exit();
?>

Would you care to explain what this has to do with Mobile Development?

I assumed perhaps incorrectly that there are Android developers using JSON. I am trying to gather the data via HttpResponse on the Android platform and there is apparently a better way to get the information. I am new to Android development and I have tried HttpClient POST and GET methods as well as WebView and I am just looking for some guidance. IS this the wrong forum to ask this kind of question?

I am willing to use whatever works. I have already tried an XML approach and a webview approach. This current approach gives me the information I need but I am having difficulty filtering out the unneeded information i.e. the HTML code that is also being provided when I try and grab the JSON data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.