首頁 >後端開發 >php教程 >建立動態的WML站點(三)_PHP教程

建立動態的WML站點(三)_PHP教程

WBOY
WBOY原創
2016-07-21 16:05:17968瀏覽

接著使用者必須在下一個檔案(index3.wml)中輸入。我們要求使用者輸入科目的名字或教授的姓。你要留意一下變數在頁面之間是怎麼傳送的。文法看來有點複雜,不過可以讓你了解整個過程是怎麼透過幾個檔案來完成的。
Header("Content-type: text/vnd.wap.wml");  
header("Cache-Control: no-cache, must-revalidate"); no  
header("Pragma:er("Pragma:)("Pragma: -cache");  
echo ("<?xml version='1.0'?>;");  
>;
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD/ML 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">

echo ("<POSTFIELD value='"$"."$choice".""/' name='"$choice"'>");  

echo ("<>echo ("< POSTFIELD value='"$"."${$choice}".""/' name='"${$choice}"'>");  

? >  
</GO>
</DO>
<P></P>
</CARD>
</WML> ><DO type="text" label="Go">
<GO href="index3.wml#card3" method="get">
echo ("<POSTFIELD value='"$"."$choice".""/' name='"$choice"'>");  
echo ("<POSTFIELD value='"$ choice"/' name='"choice"'>");  
? >  



</CARD>
</WML>
寫查詢程式碼

以下的檔案負責處理查詢。它的名字是query.wml,我們將更詳細地分析它。


Header("內容類型:text/vnd.wap.wml");  
printf("n");  
printf("n");  
printf("n");  


// 下列各行是用來詢問 🎜>

$consulting_tables =  
"(professors left join teach on (professors.Id = teach.Id), subjects)"; > .Name, subjects.Subject , ";  
$consulting_columns .=  
"subjects.Cod_number, professors.Consulting_hour, professors.Consulting_place"; Cod_Subject = teach.Cod_subject ";  


// 以下各行是用來為查詢測驗時間建構SQL語句的  

$exams_tables= "(exams left join professors ON (exams. = professors. ), subjects)";  
$exams_columns= "subjects.Subject , subjects.Cod_number, professors.Surname, ";  
$exams_columns.= kamk. , exams.Test";  
$exams_query= "exams.Cod_Subject = subjects.Cod_Subject ";  

//// 查詢是用來為查詢句子測驗

if ($exams_data) {  

switch($exams_data) {  
case "subject":  
$exams_3query.Ssubect; ";  
break;  
case "surname":  
$exams_query.= " and professors.Surname like '%$surname%'";  break; 🎜>

// 以下各行是用來為查詢課程時間的sql語句增加查詢限制

if ($consulting_data) {  
switch($consulting_data) { "subject":  
$consulting_query  
.= " and subjects.Subject like '%$subject%'";  
;  break;  
}  
}  


// 處理與資料庫的連線function connect($tables, $data, $condition_passed) {  
//  
// put your password and username in next line  
// "$ ,"***","***");  

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

// 這個函數產生課程時間的wml程式碼

function consulting_print($consulting_result) {  
global $file;  
printf("n);  (" <P>Receiving hours  

n");  
while ($myrow = mysql_fetch_row($consulting_result)) { @ 1]</P​​>n");  
printf(" <P>$myrow[2]</P>n");  
printf(" <P>$myrow[3]</>< n");  
printf(" <P>$myrow[4]</P>n");  
printf(" <P>$myrow[5]</P>n"); >}  
printf("</CARD>n");  
}  


// 這個函數產生測驗時間表的wml代碼

exams_result) {  
global $file;  
printf("<CARD id='"card1"' title='"hours"'>n");  
printf(" <.P. >
n");  
while ($myrow = mysql_fetch_row($exams_result)) {  
printf(" <P>$myrow[2], $myrow[3]</>n" ;  
printf(" <P>$myrow[0]</P>n");  
printf(" <P>$myrow[1]]</P>n"); (" <P>$myrow[4], $myrow[5]</P>n");  
printf(" <P>$myrow[7]</P>n"); (" <P>$myrow[6]</P>n");  
}  
printf("</CARD>n");  
} / 檢查你時候選擇授課時間或測驗時間,連接資料庫並且呼叫產生wml程式碼的函數

if ($consulting_data) {  
$connection_result =  
connect($consulting_$consulting_fconsulting_fconsulting_$consulting_H. consulting_query);  
consulting_print($connection_result);  
}
if ($exams_data) {  
$connection_result =  
connect($exams_tables, $ exams_columns, $ s_query); f("< /WML>n");  

? >  

  好,完成了。你已經建立了首個基於MySQL資料庫的PHP/WML頁面了,自己繼續實踐一下吧。 


http://www.bkjia.com/PHPjc/315787.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315787.htmlTechArticle接著使用者必須在下一個檔案(index3.wml)中輸入。我們要求使用者輸入科目的名字或教授的姓。你要留意一下變數在頁面之間是怎麼傳送的。 ...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn