I am trying to get data in html page from mysql database using GET/POST
method with help of json
and Jquery
. The scenario is i am taking two value from user interface (searchtenant.html
) and POST it to newterms2.html
where newterms2.html
is getting data from tenantlistmob2.php
using JSON
.
My searchtenant.html
is
<!DOCTYPE HTML>
<html>
<body>
<form action="newterms2.html" method="post">
First Name:<input type="text" id="fname" name="fname" placeholder="First Name" required="required"/><br /><br />
Last Name: <input type="text" id="lname" name="lname" placeholder="Last Name" required="required"/><br /><br />
<input type="submit" id="save" name="search" value="Search"/>
</form>
</fieldset>
</body>
</html>
My tenantlistmob2.php
is
<?php
include('connection.php');
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$result = mysql_query("SELECT * FROM `tenanttemp` WHERE `TenantFirstName`='$fname' and `TenantLastName`='$lname'");
//$result = mysql_query("SELECT * FROM `tenanttemp`");
while ($row = mysql_fetch_assoc($result))
{
$array[] = array($row['TenantFirstName']);
}
echo json_encode($array);
?>
My newterms2.html
is like
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="myjquery.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
jQuery.getJSON("tenantlistmob2.php", function (jsonData) {
jsonData= eval(jsonData);//get json array
for (i = 0; i < jsonData.length; i++)//iterate over all options
{
for ( key in jsonData[i] )//get key => value
{
var tblRow = "<tr>" + "<td>" + "<a href='#'>" + jsonData[i][key] + "</a>" + "</td>" + "</tr>"
$(tblRow).appendTo("#getname tbody");
}
}
});
});
</script></head>
<body>
<form name="index">
<div id="getname2"></div>
<div>
<table id="getname" border="1">
<thead>
<th>Name</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</form>
</body>
</html>
This is the total scenario.If i call tenantlistmob2.php
directly from searchtenant.html
using POST
method it works fine.But i need html page to show the data because i will use this html page for both android
and iPhone
. The query ($result = mysql_query("SELECT * FROM tenanttemp");
) works fine and return properly to newterms2.html
.But when i use POST
ed data ($result = mysql_query("SELECT * FROM tenanttemp WHERE TenantFirstName='$fname' and TenantLastName='$lname'");
) it works properly in php but not returning data to newterms2.html
page.
What is the solution? I like to get the data in html page.Please help.
Thanks in advance.