明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

創(chuàng)建動(dòng)態(tài)的WML網(wǎng)站(3)

[摘要]接著用戶必須在下一個(gè)文件(index3.wml)中輸入。我們要求用戶輸入科目的名字或者教授的姓。你要留意一下變量在頁(yè)面之間是怎樣傳送的。語(yǔ)法看來(lái)有點(diǎn)復(fù)雜,不過(guò)可以讓你了解整個(gè)過(guò)程是怎樣通過(guò)幾個(gè)文件來(lái)完成的。 <?php Header("Content-type: text/vnd...
接著用戶必須在下一個(gè)文件(index3.wml)中輸入。我們要求用戶輸入科目的名字或者教授的姓。你要留意一下變量在頁(yè)面之間是怎樣傳送的。語(yǔ)法看來(lái)有點(diǎn)復(fù)雜,不過(guò)可以讓你了解整個(gè)過(guò)程是怎樣通過(guò)幾個(gè)文件來(lái)完成的。
<?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).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>
寫(xiě)查詢代碼

以下的文件負(fù)責(zé)處理查詢。它的名字是query.wml,我們將更詳細(xì)地分析它。

<?php  

Header("Content-type: text/vnd.wap.wml");  
printf("<?xml version="1.0"?>n");  
printf("n");  
printf("n");  


// 以下各行是用來(lái)為查詢授課時(shí)間構(gòu)造SQL語(yǔ)句的  


$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 ";  


// 以下各行是用來(lái)為查詢測(cè)驗(yàn)時(shí)間構(gòu)造SQL語(yǔ)句的  

$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 ";  

// 以下各行是用來(lái)為查詢測(cè)驗(yàn)時(shí)間表的sql語(yǔ)句增加查詢限制


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


// 以下各行是用來(lái)為查詢授課時(shí)間的sql語(yǔ)句增加查詢限制

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


// 處理與數(shù)據(jù)庫(kù)的連接  


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


// 這個(gè)函數(shù)產(chǎn)生授課時(shí)間的wml代碼

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


// 這個(gè)函數(shù)產(chǎn)生測(cè)驗(yàn)時(shí)間表的wml代碼

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


// 檢查你時(shí)候選擇授課時(shí)間或者測(cè)驗(yàn)時(shí)間,連接數(shù)據(jù)庫(kù)并且調(diào)用產(chǎn)生wml代碼的函數(shù)

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

?>  

  好,完成了。你已經(jīng)建立了首個(gè)基于MySQL數(shù)據(jù)庫(kù)的PHP/WML頁(yè)面了,自己繼續(xù)實(shí)踐一下吧。