I need a small hint. Let’s say there’s a code like:
<?php
$test = mysql_query("SELECT * FROM test WHERE id='1'");
while($row = mysql_fetch_array($test))
{
echo "<tr>";
echo "<td>" . $row['platform_name'] . "</td>";
echo "<td>" . $row['scan_frequency'] . "</td>";
echo "<td><input id='freq' type='text' /></td>";
echo "<td><input id='date1' class='datepicker' type='text' /></td>";
echo "<td><input id='date2' class='datepicker' type='text' /></td>";
echo "<td><button id='save'>Save</button></td>";
echo "</tr>";
}
?>
The logic is that when I run a page, I get platform name and scan frequency fetched from table test as supposed to. Then I need to fill out three inputs (new frequency and dates, which are in format yy-mm-dd) and send it back (update/set) using ‘save’ button to table test. How can I do it with AJAX/PHP?
Thanks in advice!
Here’s a small hint. 😉
You link the button attribute onclick to a javascript function (e.g. fetch_new_data). Then you define the function fetch_new_data, which sends an ajax request to the server. The server processes the ajax request, selects the new data, packages it as xml or json and sends it back to the client. On return of the data, you lookup the position of the table, where you want to insert the new data and extend the table with a few new rows.
You can look for jquery, which simplifies several of these tasks on the client side. At the server side, for PHP and JSON, see PHP – JavaScript Object Notation and any tutorial or example covering PHP+JSON and/or PHP+AJAX.