| Java menu knowledge base PHP script for dynamic menus
Contributed by: K.M.Newnham, consultant for business application
development using open source development tools.
This article shows you how to use the PHP programming language to dynamically
populate the options in an IMINT applet with data that is stored in a
MySQL database.
Requirements
- A web server running PHP4, on any supported environment.
- A mySQL database server (although the supplied script samples are easily modifiable to be run with any database system supported by PHP).
- The scripts accompanying this article - click here to download.
- An IMINT applet that allows you to specify the name of the index file, which
is usually done with the menufile parameter. Trial versions as well as
release versions of most applets can be used in this way, so you can practice
database retrieval with the applets before buying.
- An understanding of IMINT's XIXL eXtensible IndeXing Language.
Strategy
In any applet-database retrieval system for IMINT applets, whether you use PHP or any other
language, there are basically three elements involved.
- The database: compiled and ready on the server.
- The database retrieval script: on the server, written by you, or borrowed
from this article and perhaps modified by you. PHP is just one of the
languages which can be used. This script is the interface between the database
and the applet. It selects data from the database and reformats it before passing
it to the applet.
- The applet: this is on the client and simply waits for the database
retrieval script to send it the menu as a stream of correctly formatted
characters. NB: while the applet is also uploaded to the server together with the
retrieval script and database, you must remember that the applet actually doesn't
do anything until it has been downloaded to the client machine of the website's visitor.
Query strings: the applet may do more than just wait for the data. When the applet requests the
data from the retrieval script, it can also (if you set it up this way) pass along
a query string with the request. Depending on the contents of this query string, the
database retrieval script could select different sets of data from the database.
Implementation
- The database: click here to see a sample mySQL source file
and click here to download it.
This sample file (menus.sql) is ready to be loaded into a mySQL database to provide a demonstration database table.
To load the mySQL source file:
- From the command prompt, start a mySQL session.
- Select a suitable database or create a new one e.g.
- use test; or
- create database test;
- use test;
- Load the source file e.g. source menus.sql;
The source file will load, creating the table and populating it with the demonstration data.
- The database retrieval script: click here to see
a sample PHP source file and click here to download it.
Place this file (menus.php) in the same directory as the HTML file that creates the applet.
This file must be modified to pass the correct connection parameters to the mySQL database.
The sample source file contains very detailed comments explaining how to modify it to
suit your needs.
- The applet: this can access the database retrieval script
at different times during its operation, depending on your needs.
- When it first starts. Use the menufile parameter (or with some
applets, a different parameter - see instructions) like this:
<PARAM NAME=menufile VALUE=menus.php>
- During operation when the user clicks a specific menu item and triggers
a new index load. Use the DRILL command like this:
"TEXT:menu item" "1" "" "DRILL:menus.php" "(Load new menu)"
- During operation, using a remote javascript control to trigger
a new index load (if the applet supports this). Use the drill() method like this:
document.myApplet.drill('menus.php');
Query strings: while the sample PHP file does not support this as written, theoretically all
of the above requests by the applet for a new menu could have query strings
attached by changing menus.php to (e.g.) menus.php?my_query.
Troubleshooting
If you set up everything in the way described and find it doesn't work, you
will find it difficult to track down the cause if you just look at the applet
on your screen. Probably the applet will just show "error 4", which means
it couldn't find any menu, or it may show one of the error codes for an
incorrectly formatted index.
To make things easier for yourself, you should check the database
retrieval script during development by entering the URL used by the
applet directly into the browser address bar. If your database
retrieval script is written correctly, then a simple text file
output should appear in the browser which is identical to a typical
XIXL index file. This way you can check the formatting of the
index directly.
|
|