Establish a dynamic WML site (iii) _php Foundation

Source: Internet
Author: User
The user must then enter in the next file (INDEX3.WML). We require the user to enter the subject's name or the professor's surname. You need to be aware of how variables are transmitted between pages. The syntax seems a bit complicated, but it lets you know how the whole process is done with several files.
? 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 ' surname (or part of it). N");
else if (${$choice} = = "Subject") {
Echo ("The subject (or part of it). N");
} else {
Echo ("Maybe There is some PROBLEM.N");
Echo ("<input name= '" ${$choice} "' Type= '" text "'");

? >
<do type= "text" label= "Go"
<go href= "QUERY.WML" method= "get" >
? Php

Echo ("<postfield value=" "$".) $choice "." " /' name= ' "$choice" "");

Echo ("<postfield value=" "$".) ${$choice} "." " /' Name= ' "${$choice}" ' ");

? >
</GO>
</DO>
<p> </P>
</CARD>
</WML>



<do type= "text" label= "Go"
<go href= "Index3.wml#card3" method= "get" >
? Php
Echo ("<postfield value=" "$".) $choice "." " /' name= ' "$choice" "");
Echo ("<postfield value= '" $choice "/' name= '" Choice "");
? >



</CARD>
</WML>
Write Query code

The following files are responsible for processing queries. Its name is QUERY.WML, and we will analyze it in more detail.

? Php

Header ("CONTENT-TYPE:TEXT/VND.WAP.WML");
printf ("A;?") XML version= "1.0"? >n ");
printf ("n");
printf ("n");


The following lines are used to construct the SQL statement for the query instruction time.


$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 following lines are used to construct the SQL statement for the query quiz time.

$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 following lines are used to add query restrictions to the SQL statement for the query quiz schedule


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 following lines are used to increase the query limit for SQL statements that query session time

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
}
}


Handling Connections to databases


Function Connect ($tables, $data, $condition _passed) {
//
Put your password and username on next line
//

$db = Mysql_pconnect ("localhost", "* * *", "* * *");

Put your database name on 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 produces the WML code for the session time

function Consulting_print ($consulting _result) {
Global $file;
printf ("n");
printf ("<p> Receiving hours

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 produces the WML code for the quiz schedule

function Print_exams ($exams _result) {
Global $file;
printf ("<card id= '" Card1 "' title= '" Hours "' >n");
printf ("<p> Examinations hours

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");
}


Check the time you choose to teach or quiz, connect to the database, and invoke the function that produces the 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");

? >

Okay, it's done. You've built the first PHP/WML page based on the MySQL database, and keep practicing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.