C:\php\php4isapi.dllC:\php\php.exeprofessors contains data about professors subjects contains data about subjectsexams contains data about examsteach contains the relations between
the professors and their subjectsCREATE TABLE professors ( Id int(11) DEFAULT '0' NOT NULL auto_increment, Surname varchar(24) NOT NULL, Name varchar(24) NOT NULL, Email varchar(48) DEFAULT 'Not avaliable', Cod_course varchar(16) DEFAULT 'Not avaliable', Consulting_hour varchar(128) DEFAULT 'Not avaliable', Consulting_place varchar(128) DEFAULT 'Not avaliable', PRIMARY KEY (Id) );
Id is the field for associating
an unique identifier with each professor and is the
key of the table. The other fields, Surname, Name, Email specifies
the surname, the name and the e-mail address for
each professor. Cod_course assumes unique
values identifying the subjects. Finally, Consulting_hour and Consulting_place specify
the receiving time and the place for receiving.CREATE TABLE subjects ( Subject varchar(96) NOT NULL, Cod_Subject varchar(24) NOT NULL, Cod_number varchar(12) NOT NULL, PRIMARY KEY (Cod_subject ) );
Cod_subject is
the field containing the unique name adopted by the
University for the subject and is the key of the
table. Cod_number is a numeric field containing
a number grouping different courses on the same subject.
CREATE TABLE exams (
Cod_Subject varchar(24) NOT NULL,
Id int(11) NOT NULL,
Date date DEFAULT '0000-00-00',
Time time DEFAULT '00:00:00',
Room varchar(64),
Test varchar(16) DEFAULT 'Oral'
);
Cod_subject again contains
the unique name adopted by the University for the
subject,Id is the unique identifier for the
professors, Date, Time, and Room,
record the date, the time and the place where exams
will take place; Test is for the type of the
exam (written, oral, or anything else).CREATE TABLE teach ( Cod_Subject varchar(16) NOT NULL, Id int(11) DEFAULT '0' NOT NULL, PRIMARY KEY (Id, Cod_subject ) );
teach the two
fields form the key and are necessary to know who
is teaching what.
<?php
Header("Content-type: text/vnd.wap.wml");
Header("Cache-Control: no-cache, must-revalidate");
Header("Pragma: no-cache");
echo ("<?xml version='1.0'?>");
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml" >
<wml>
<card id="card1" title="UNITO/Database">
<p> You can search for professors' consulting hours
or for examinations timetables.
<select name="choice" value="1" title="Research">
<option value="exams_data">Examinations timetables</option>
<option value="consulting_data">Consulting hours</option>
</select>
<do type="text" label="Go">
<go method="get" href="index2.wml#card2"> <postfield name="choice" value="$(choice)" /> </go>
</do>
</p>
</card>
</wml>
<?xml
version='1.0'?>, embed it into PHP code
to avoid confusion.$choice.
<?php
Header("Content-type: text/vnd.wap.wml");
Header("Cache-Control: no-cache, must-revalidate");
Header("Pragma: no-cache");
echo ("<?xml version='1.0'?>");
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card2" title="Kind of research">
<p>
<?php
echo ("You are checking ");
if ($choice == "exams_data") {
echo (" examinations timetables.<br />\n");
} else if ($choice == "consulting_data") {
echo (" consulting hours.<br />\n");
} else {
echo ("I don't know what and there is some problem.<br />\n");
}
?>
</p>
<p> You can search by surname (either exact or partial)
or by subject (either exact or partial).<br />
Select the kind of research.</p>
<p>
<select name="<?php echo ("$choice");?>" value="surname" title="research">
<option value="surname"> professor's name</option>
<option value="subject"> subject</option>
<do type="text" label="Go">
<go method="get" href="index3.wml#card3">
<?php
echo ("<postfield name=\"$choice\" value=\"$"."$choice"."\"/>");
echo ("<postfield name=\"choice\" value=\"$choice\"/>");
?>
</go>
</do>
</p>
</card>
</wml>
Again the decision is stored into variable $choice.
<?php
Header("Content-type: text/vnd.wap.wml");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo "<?xml version='1.0'?>";
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml" >
<wml>
<card id="card3" title="Name">
<?php
echo ("<p>Insert ");
if (${$choice} == "surname") {
echo ("professor's surname (or part of it).<br />\n");
} else if (${$choice} == "subject") {
echo ("the subject (or part of it).<br />\n");
} else {
echo ("Maybe there is some problem.<br />\n");
}
echo ("<input type=\"text\" name=\"${$choice}\" />");
?>
<do type="text" label="Go">
<go method="get" href="query.wml">
<?php
echo ("<postfield name=\"$choice\" value=\"$"."$choice"."\"/>");
echo ("<postfield name=\"${$choice}\" value=\"$"."${$choice}"."\"/>");
?>
</go>
</do>
<p>
</p>
</card>
</wml>
query.wml
and we will analyze it more in depth.
<?php
Header("Content-type: text/vnd.wap.wml");
printf("<?xml version=\"1.0\"?>\n");
printf("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" "
."\"http://www.wapforum.org/DTD/wml_1.1.xml\" >\n");
printf("<wml>\n");
// The next lines are used to build
// the sql query for receiving hours:
$consulting_tables =
"(professors left join teach on (professors.Id = teach.Id), subjects)";
$consulting_columns =
"professors.Surname, professors.Name, subjects.Subject , ";
$consulting_columns .=
"subjects.Cod_number, professors.Consulting_hour, professors.Consulting_place";
$consulting_query=
"subjects.Cod_Subject = teach.Cod_subject ";
// The next lines are used to build the
// sql query for examination timetables:
$exams_tables= "(exams left join professors ON (exams.Id = professors.Id), subjects)";
$exams_columns= "subjects.Subject , subjects.Cod_number, professors.Surname, ";
$exams_columns.= "professors.Name, exams.Date, exams.Time, exams.Room, exams.Test";
$exams_query= "exams.Cod_Subject = subjects.Cod_Subject ";
// The next lines are used to add options to the sql query for examination timetables:
if ($exams_data) {
switch($exams_data) {
case "subject":
$exams_query.= " and subjects.Subject like '%$subject%'";
break;
case "surname":
$exams_query.= " and professors.Surname like '%$surname%'";
break;
}
}
// The next lines are used to to add options to the sql query for receiving times:
if ($consulting_data) {
switch($consulting_data) {
case "subject":
$consulting_query
.= " and subjects.Subject like '%$subject%'";
break;
case "surname":
$consulting_query.= " and professors.Surname like '%$surname%'";
break;
}
}
// handles the connection with database
function connect($tables, $data, $condition_passed) {
//
// put your password and username in next line
//
$db = mysql_pconnect("localhost","***","***");
// put your database name in next line
mysql_select_db("lanfranchi_co_uk",$db);
$sql = "SELECT $data FROM $tables WHERE $condition_passed order by professors.Surname";
$result = mysql_query($sql,$db);
return $result;
}
// this function writes the wml code for receiving hours
function consulting_print($consulting_result) {
global $file;
printf("<card id=\"card1\" title=\"hours\">\n");
printf("<p>Receiving hours</p>\n");
while ($myrow = mysql_fetch_row($consulting_result)) {
printf("<p>$myrow[0], $myrow[1]</p>\n");
printf("<p>$myrow[2]</p>\n");
printf("<p>$myrow[3]</p>\n");
printf("<p>$myrow[4]</p>\n");
printf("<p>$myrow[5]</p>\n");
}
printf("</card>\n");
}
// this function writes the wml code for examination timetables
function print_exams($exams_result) {
global $file;
printf("<card id=\"card1\" title=\"hours\">\n");
printf("<p>Examinations hours</p>\n");
while ($myrow = mysql_fetch_row($exams_result)) {
printf("<p>$myrow[2], $myrow[3]</p>\n");
printf("<p>$myrow[0]</p>\n");
printf("<p>$myrow[1]]</p>\n");
printf("<p>$myrow[4], $myrow[5]</p>\n");
printf("<p>$myrow[7]</p>\n");
printf("<p>$myrow[6]</p>\n");
}
printf("</card>\n");
}
// checks if you selected reciving hours or examination
//timetables, connects to the database and calls the
//function to the write wml code
if ($consulting_data) {
$connection_result =
connect($consulting_tables, $consulting_columns, $consulting_query);
consulting_print($connection_result);
}
if ($exams_data) {
$connection_result =
connect($exams_tables, $ exams_columns, $ exams_query);
print_exams($connection_result);
}
printf("</wml>\n");
?>