We’ll also need some PHP to finish off this example; in a new page in your text editor add the following code:
$host = "localhost";
$user = "root";
$password = "your_password_here";
$database = "prototip";
$server = mysql_connect($host, $user, $password);
$connection = mysql_select_db($database, $server);
$param = $_GET["q"];
//query the database
$query = mysql_query("SELECT * FROM contents WHERE tip LIKE '$param%'");
//get the data
$row = mysql_fetch_assoc($query);
$contents = $row["content"];
//return matching data
Save this in the main prototipdirectory as contents.php. This is a very basic PHP script for getting data out of a database that matches the incoming parameter which is available under the $_GETsuperglobal.
I’d like to point out that this is the minimum amount of code required for this type of operation; security has not been a consideration in this example, so this file should not be used in a mission-critical application that is publicly available.
To see this example, you’ll need to copy the prototip directory (containing the libraries, plugins and files that we’ve made so far) into a content-serving directory of your web server. You’ll also need a MySQL database called prototip containing a table called contents, with the name of each tooltip in a column called tip and the content for each tooltip in a column called content. To make it easier to load data into this table once created, I’ve included a text file in the source code download for this article which can be used to load the data.
Once this has been done, you should be able to run the new page and see something like this: