Capt Spaghetti 0 Newbie Poster

I currently have two php files that I need to combine so I can eliminate the use of the "<a href" construct. The first file allows the user to enter a city and state to search for organizations. After entering the city and state the user is presented with a table which contains the list of organizations with their IDs. When the user selects a particular ID I am using json_encode to send "ONLY" JSON data back to my Android application. Right now I am getting everything. If I can get help combining the files I may still need to take this to the Mobilt Development group but I thought I would start here. Any help would be appreciated.

First file: orgloc12.php

<html> 
<body style="background-color:#33990f">
<head> 
<title>Locate Organizations</title> 
</head> 
<body> 

<?php 

if (!$_REQUEST['Submit']) { 
        citystate_form(); 
} else { 
    select_oneorg();
} 

function citystate_form() {

?> 
<form name="citystate" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <b><FONT COLOR="#FFFAFA">City:</FONT></b> <input type="text" name="orgcity"><br>
    <b><FONT COLOR="#FFFAFA">State:</FONT></b> 
    <select name="orgstate"><br>
    <option selected="selected" value="">(Select)</option>
    <option value="AK">AK</option>
    <option value="AL">AL</option>
    <option value="AR">AR</option>
    <option value="AZ">AZ</option>
    <option value="CA">CA</option>
    <option value="CO">CO</option>
    <option value="CT">CT</option>
    <option value="DC">DC</option>
    <option value="DE">DE</option>
    <option value="FL">FL</option>
    <option value="GA">GA</option>
    <option value="HI">HI</option>
    <option value="IA">IA</option>
    <option value="ID">ID</option>
    <option value="IL">IL</option>
    <option value="IN">IN</option>
    <option value="KS">KS</option>
    <option value="KY">KY</option>
    <option value="LA">LA</option>
    <option value="MA">MA</option>
    <option value="MD">MD</option>
    <option value="ME">ME</option>
    <option value="MI">MI</option>
    <option value="MN">MN</option>
    <option value="MO">MO</option>
    <option value="MS">MS</option>
    <option value="MT">MT</option>
    <option value="NC">NC</option>
    <option value="ND">ND</option>
    <option value="NE">NE</option>
    <option value="NH">NH</option>
    <option value="NJ">NJ</option>
    <option value="NM">NM</option>
    <option value="NV">NV</option>
    <option value="NY">NY</option>
    <option value="OH">OH</option>
    <option value="OK">OK</option>
    <option value="OR">OR</option>
    <option value="PA">PA</option>
    <option value="PR">PR</option>
    <option value="RI">RI</option>
    <option value="SC">SC</option>
    <option value="SD">SD</option>
    <option value="TN">TN</option>
    <option value="TX">TX</option>
    <option value="UT">UT</option>
    <option value="VA">VA</option>
    <option value="VT">VT</option>
    <option value="WA">WA</option>
    <option value="WI">WI</option>
    <option value="WV">WV</option>
    <option value="WY">WY</option>
</select><br/>
    <b><FONT COLOR="#FFFAFA">Org Name:</FONT></b> <input type="text" name="orgname"><br><br/>
    <input type="submit" name="submit" value="Find Organizations">
</form> 

<?php 
}

function select_oneorg() {

?> 
<h3 style="background-color:#33990f"<FONT COLOR="#FFFAFA">AceCapper</FONT></h3> 

<?php
$user="username";
$password="userpassword";
$database="mydatabase";
$connect = @mysql_connect("mysqlv",$user,$password);
@mysql_select_db($database) or die (mysql_error());
/* echo "Connected"; */
//
// Select organizations based on passed variables for 
// orgcity=WILMINGTON&orgstate=DE&orgname=ARTHRITIS
//
$query = "SELECT orgname, org_id FROM organizations WHERE ";
if (strlen($_GET['orgname']) > 0)
    $query .= " organizations.orgname LIKE '%{$_GET['orgname']}%' AND ";
$query .= "organizations.orgcity = '{$_GET['orgcity']}' AND organizations.orgstate = '{$_GET['orgstate']}'";
/* Temporary ECHO of the $sql string */ 
echo "<p>" . $query . "</p>";
//
// 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(); 
} 

?>
<!-- __   -->
<!-- format table  -->
<!-- __   -->
<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">Org Name</font></th>
<th><font face="Arial, Helvetica, sans-serif";font color="#FFFAFA">Org 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 = 
'http://www.myserver.com/graborginfo9.php?varID=".$row['org_id']."'>".$row['org_id']."</td></a>";

}
?>
</table>;
</div>
<?php

/* Closes Connection to MySQL server */ 

mysql_close ($connect);

citystate_form(); 
}
?>

Second file: graborginfo9.php

<html>
<body style="background-color:#33990f">

<?php

// connect include
require ("connect.php");

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

/* Temporary ECHO of the $sql string */ 
/* echo "<p>" . $query . "</p>"; */

$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))
{
    $output[]=$row;
    echo(json_encode($output));
}

/* Closes Connection to MySQL server */ 

mysql_close ($connect); 
exit();
?> 

</body></html>
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.