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();
?>