Nov 21

I managed to make the Ajax.InPlaceEditor do some work for me. I had no idea what was wrong with my original approach until today, when I used Firebug to inspect the sent and returned values of my code. It was just then when I realised that there was no actual return value.

1
2
3
4
<h1 id="test">Test value</h1>
<script type="text/javascript">
        new Ajax.InPlaceEditor('test', 'output.php',{callback: function(form, value) { return 'name=' + escape(value)}});
      </script>

The solution was easy, the return value of the InPlaceEditor’s method needed a bit altering:

And here is output.php

1
2
3
$var = $_POST['name'];
echo $var;
?&gt;

Easy :)

Sep 20

Ever heard of Google Suggest? I bet you did. Let me show you a simple Ajax-PHP-MySQL code based on suggest. This script will search a database and nest your result while and when you type.

I have used and modified the example shown on W3Schools.com.

What I have done, I left the Javascript file as it is and created a PHP file and instead of filling up the arrays I do the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
include("connection.php");
function suggest() {
//get the q parameter from URL
$q=addslashes($_GET["q"]);
 
//connect to database
makeConnection();
//make the query
$select = "SELECT * FROM (table) WHERE (field) LIKE '".$q."%'";
$result = mysql_query($select) or die (mysql_error());
//do whatever you want to do with the result
//disconnect from database
disconnect();
}