I am building a php page something like this ..
A jquery syntax decleration
<script type="text/javascript" src="jquery.js"></script></script>
<script type="text/javascript">
function get(){
$.post('output.php', { name: form.name.value },
function(output) {
$('#age').html(output).show();
}) ;
}
</script>
The form structure .
The information of the id entered here will be fetched from a database using output.php file
<body>
<p>
<form name="form">
id:
<input type ="text" name="name"><input type ="button" name="Submit_1"
value="Get
Existing Data" onclick="get();">
</body>
Output.php echos the following values from the database which will be displayed on the same page using jquery & ajax
$age= mysql_query("SELECT title FROM parentid WHERE id ='$name'");
$age_num_rows = mysql_num_rows($age);
if ($age_num_rows==0)
echo "id does not exist";
else
{
$sql ="SELECT * FROM parentid WHERE id = '$name'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$abc_output= "Existing data of the record <br />";
$abc_output .="Title: " . $row['title'] . "<br />" ;
$abc_output .="Report No: " . $row['reportno'] . "<br />" ;
$abc_output .="URL: " . $row['calc_url'] . "<br />" ;
$abc_output .="Institution: " . $row['institution'] . "<br />" ;
}
}
echo $abc_output;
The output of the above program will be something like
Form structure for id:
After entering id info of title,report no. ..will be displayed on the same page
..
Now what i want to do is
I will be creating the form structure for title , etc.,
something like this..
<p>title:<input type="text" name="title"/></p>
<p>reportno:<input type="text" name="reportno"/></p>
<p>url: <input type="text" name="calc_url"/></p>
The information that is obtained from the database should be inserted into these forms ..these forms will be on the initial page..
How can i do this??
Thanks for u r time..
I suggest you create an associative array to hold the values you’re returning rather than appending the strings. You can encode that object as JSON using json_encode. http://www.php.net/manual/en/function.json-encode.php
then you can access the array by the key in javascript. Something like..
where “output” is the json object you returned.