How to fill multiple input fieds with one MySQL query


Problem :

I know how to fill a single INPUT field with an ajax call like this. Suppose this is GO.PHP:

$qry = mysql_query("SELECT * FROM reviews WHERE id = ".$_GET['param']." "); 
while($review = mysql_fetch_array($qry)) {
    echo $review['description'];
}

When I click the following:

<a class="editlink" id="<?php echo $review['id']; ?>" href="#"><?php echo $review['title']; ?></a>

I call ajax like this:

$(".editlink").click(function() {
    $.get("go.php", {param: $(this).attr('id')}, 
        function(data) {
            $('textarea#area1').html(data);
        });    
    return false;
});

'data' is filled by 'echo $review["description"]' and passed to TEXTAREA which is populated correctly. Ok, up to now everything works. But I don't know how to populate two, three, four, etc fields with the same mySQL query. Suppose I also had:

<input type="text" name="title">
<input type="text" name="date">
<input type="text" name="author">

How do I have to pass 'data' (GO.PHP) to populate all the INPUT fields?



Solution :

I would generate and send a JSON string with GO.PHP. The JSON string from GO.PHP would be something like:

 {"title" : "mytitle", "date" : "mydate", "author" : "myauthor"}

Then on the client side:

jsonOBJ = {};
$.ajax({
  type: "GET",
  url: "go.php",
  cache: false,
  success: function(data){
     jsonOBJ = jQuery.parseJSON(data);
     for (var key in jsonOBJ) {
       $("input[name=" + key + "]").val(jsonOBJ[key]);
     }
  },
});

Mysql Tutorials

Mysql Howto..

How to wordwrap mysql data?

mysql best backup method? and how to dump backup to target directory

How to join two tables and then display the sum value of each data of a table gathering from the other table

How do I store rank for each website in MySQL using this API

How to get mysql queries if contition is matched and yet have a fallback

How to order by items based on data from two mysql tables?

How do I reload a Roo project without clearing the database?

MySQL - How to get results of Group_Concat without grouping?

mysql how to restore data for part of a table

how to reuse subquery result in mysql

Find how many (googlemap) polygons near x distance of a point

How to write a string variable inside mysql query?

Python3.x how to share a database connection between processes?

how to fetch all data from one table in mysql?

How i can convert a mdb file to mysql file or mysql commands with PHP?

How to use cron jobs with php mysql request

How to insert data only if data doesn't already exist in MYSQL?

I want to show relational data, when theres data missing in a mysql query

How to write this simple MySQL JOIN query?

How to implement Slick + MySQL + SecureSocial?

how to create index table based on an existing table in Mysql

How to upload image to mysql database iOS application

How to generate a fixture list in PHP/MySQL?

How to use procedure parameters variable in query inside procedure

How to set a relation cardinality of one to one in mysql?

How to write mySQL trigger that allows null values while still checking referncial integrity?

How to compare arraylist items to mysql database using jdbc connection from Asynctask?

I'm using spring, hibernate and mysql. How can I let my app create the table automatically

How to update a mysql column with php?

How can I put markup between each MySQL field result?