Learning WML -Scripting Tips And Integration With PHP
Project Description
In our last article we implemented a simple phone list using PHP and MySQL. The basic premise was to give salespeople access to a central contact database without the need of synchronizing their phones/PDAs. The script pulled contact data from a database, displayed the records, and dialed the selected record. This project will expand on that example, adding the following features:
- The contact database will include address information.
- There will be more contacts, requiring the list to be displayed a few records at a time.
- A search feature will be added.
Because there will be more than one feature (list and search), we will also need a menu so the user can choose what feature he or she wants. Each screen will also need a way to return to the menu.
PHP Script Outline
If $cmd is empty, set it to "Menu" If $cmd is set to "Menu," display the Menu card If $cmd is set to "List," display the List card If $cmd is set to "Display," display the Display card, with the appropriate record If $cmd is set to "Search," display the Search card When a function is chosen, set $cmd appropriately and recursively call self.
The search function will search through the database looking for first or last names that meet the text entered in the search card. The list function will display five records at a time and will include options for moving to the next set of five records or returning to the home menu. Each option (record or link) will have a quick key. Essentially, the list will resemble the following:
- <DB record>
- <DB record>
- <DB record>
- <DB record>
- <DB record>
- [Next 5 link]
- [Home link]
Selecting a record results in displaying all of the data associated with the record, along with "dial" and "home" links.
The Contact List
Our contact database will contain the following data:
First |
Last |
Phone |
Address |
City |
State |
Zip |
Last |
Jack |
Hampton |
317-555-2200 |
213 Main St |
Indianapolis |
IN |
46222 |
2002-08-22 |
Samuel |
Marks |
317-555-8764 |
2 Northridge Dr |
Fishers |
IN |
46203 |
2002-08-22 |
Sally |
Nash |
317-555-8765 |
644 Innovation Pl |
Ft Wayne |
IN |
46875 |
2002-08-22 |
Bill |
Haskins |
317-555-8766 |
201 W 103rd |
Indianapolis |
IN |
46240 |
2002-08-24 |
Jill |
Payton |
317-555-0098 |
55 W 96th St |
Westfield |
IN |
46222 |
2002-08-22 |
Mary |
Martinez |
317-555-7544 |
9433 E. 75th Ave |
Greenwood |
IN |
46784 |
2002-08-22 |
Ned |
Tanner |
317-555-9877 |
77 E Marchen |
Ft Wayne |
IN |
46875 |
2002-08-23 |
Bruce |
Wilten |
317-555-1111 |
3 Prospect |
Indianapolis |
IN |
46038 |
2002-08-22 |
Naomi |
Waters |
317-555-4323 |
1121 Central Pl |
Westfield |
IN |
46055 |
2002-08-22 |
Angela |
Renault |
317-555-0988 |
5674 E 6th Ave |
Noblesville |
IN |
46234 |
2002-08-22 |
Markus |
Elliot |
317-555-3232 |
9755 Carter |
Indianapolis |
IN |
46250 |
2002-08-22 |
Steve |
Albert |
317-555-5444 |
95 Crescent Dr |
Indianapolis |
IN |
46250 |
2002-08-26 |
Martin |
Rolfsen |
317-555-6767 |
5678 E 7th Ave |
Indianapolis |
IN |
46234 |
2002-08-22 |
Lisa |
Biggins |
317-555-3644 |
7732 Allisonville |
Indianapolis |
IN |
46240 |
2002-08-22 |
Eric |
Gonday |
317-555-0500 |
9466 Pike Plaza |
Greenfield |
IN |
46533 |
2002-08-22 |
Douglas |
Poser |
317-555-0123 |
55 Tower Pl |
Noblesville |
IN |
46234 |
2002-08-24 |
John |
Palmer |
317-555-4444 |
12433 N Cumberland |
Fishers |
IN |
46038 |
2002-08-22 |
The database will also contain an "ID" field as a primary key (integer). That will serve as a unique key into each record. To create the data in MySQL, the following commands should be used:
CREATE DATABASE customers; USE customers; CREATE TABLE Phone ( Id int(11) NOT NULL auto_increment, FirstName varchar(30) default NULL, LastName varchar(30) default NULL, Phone varchar(12) default NULL, Address varchar(30) default NULL, City varchar(30) default NULL, State char(2) default NULL, Zip varchar(5) default NULL, LastUpdate date default NULL, PRIMARY KEY (Id) ) TYPE=MyISAM; INSERT INTO Phone VALUES (1,'Jack','Hampton','317-555-2200', '213 Main St','Indianapolis','IN','46222','2002-08-22'); INSERT INTO Phone VALUES (2,'Samuel','Marks','317-555-8764', '2 Northridge Dr','Fishers','IN','46203','2002-08-22'); INSERT INTO Phone VALUES (3,'Sally','Nash','317-555-8765', '644 Innovation Pl','Ft Wayne','IN','46875','2002-08-22'); INSERT INTO Phone VALUES (4,'Bill','Haskins','317-555-8766', '201 W 103rd','Indianapolis','IN','46240','2002-08-24'); INSERT INTO Phone VALUES (5,'Jill','Payton','317-555-0098', '55 W 96th St','Westfield','IN','46222','2002-08-22'); INSERT INTO Phone VALUES (6,'Mary','Martinez','317-555-7544', '9433 E 75th Ave','Greenwood','IN','46784','2002-08-22'); INSERT INTO Phone VALUES (7,'Ned','Tanner','317-555-9877', '77 E Marchen','Ft Wayne','IN','46875','2002-08-23'); INSERT INTO Phone VALUES (8,'Bruce','Wilten','317-555-1111', '3 Prospect','Indianapolis','IN','46038','2002-08-22'); INSERT INTO Phone VALUES (9,'Naomi','Waters','317-555-4323', '1121 Central Pl','Westfield','IN','46055','2002-08-22'); INSERT INTO Phone VALUES (10,'Angela','Renault','317-555-0988', '5674 E 6th Ave','Noblesville','IN','46234','2002-08-22'); INSERT INTO Phone VALUES (11,'Markus','Elliot','317-555-3232', '9755 Carter','Indianapolis','IN','46250','2002-08-22'); INSERT INTO Phone VALUES (12,'Steve','Albert','317-555-5444', '95 Crescent Dr','Indianapolis','IN','46250','2002-08-26'); INSERT INTO Phone VALUES (13,'Martin','Rolfsen','317-555-6767', '5678 E 7th Ave','Indianapolis','IN','46234','2002-08-22'); INSERT INTO Phone VALUES (14,'Lisa','Biggins','317-555-3644', '7732 Allisonville','Indianapolis','IN','46240','2002-08-22'); INSERT INTO Phone VALUES (15,'Eric','Gonday','317-555-0500', '9466 Pike Plaza','Greenfield','IN','46533','2002-08-22'); INSERT INTO Phone VALUES (16,'Douglas','Poser','317-555-0123', '55 Tower Pl','Noblesville','IN','46234','2002-08-24'); INSERT INTO Phone VALUES (17,'John','Palmer','317-555-4444', '12433 N Cumberland','Fishers','IN','46038','2002-08-22');
Page 1 of 2