<head><title>Book_o_Rama Catalog Search</title> </head><body><h1>Book_O_Rama Catalog Search</h1><form action="results.php"method="post"> Choose Search Type:<br/><select name="searchtype"><option value="author">Author</option> <option value="title">Title</option><option value="ISBN">ISBN</option></select><br/>Enter Search Term:<br/><input nwme="searchterm"type="text"><br/><input type="submit"value="search"></form></body></html><head><title>Book_o_Rama Search Results</title></head><body><h1>Book_O_Rama Search Results</h1><?php//create short variable names$searchtype=$_POST['searchtype'];$searchterm=$_POST['searchterm'];$searchterm= trim($searchterm);if (!$searchtype || !$searchterm){echo'you have not entered search details.pleasego back and try again.';}if (!get_magic_quotes_gpc()){$searchtype=addslashes($searchtype);$searchterm=addslashes($searchterm);}@ $db= new mysqli('localhost','bookorama','bookorama123','book_o_rama ');if (mysqli_connect_errno()){echo'ERROR: Could not connect to database.Please try and later.';exit;}$query = "select * from books where ".$searchtype."like'%".$seachterm."%'" ;$results = $db->query($query);$num_results = $result->num_rows;echo'<p>Number of books found: '.$num_results.'</p>';for($i=0;$i <$num_results; $i++){$row = $result->fetch_assoc();echo'<p><strong>'.($i+1).'.Title:';echo htmlsprcialchars(stripslashes($row['title']));echo'</strong><br />Author; ';echo scripslashes($row['author']);echo'<br />ISBN: ';echo scripslashes($row['ISBN']);echo'<br />Price: ';echo scripslashes($row['price']);echo'</p>';}$result->free();$db->close();?></body></html><html><head><title>Book_o_Rama Book Entry Results</title></head><body><h1>Book_o_Rama Book Entry </h1><form action="insert_book.php" method="post"><table border="0"><tr><td>ISBN</td><td><input type="text" name="isbn" maxlength="13" size="13"></td></tr><tr><td>Author</td><td><input type="text" name="author" maxlength="30" size="30"></td> </tr><tr><td>Title</td><td><input type="text" name="title" maxlength="60" size="30"></td> </tr><tr><td>Price $</td><td><input type="text" name="price" maxlength="7" size="7"></td></tr><tr><td colspan="2"><input type="submit" value="Register"></td></tr></table></form></body></html>1.switch条件语句在多个条件当中使用switch更加精巧,格式如下:switch($i){case 0:echo "输出0";break;case 1:echo "输出1";break;case 2:echo "输出2";break;default:echo "ssss";}同下面的if else语句if($i==0){echo "输出0";}elseif($i==1){echo "输出1";}elseif($i==2){echo "输出2";}else{echo "ssss";}2.break n循环控制语句也可以理解为循环中断语句,跳出循环语句break;跳出一层循环。
break n;跳出N条循环。
3.do...while循环语句do{...}while(expr)先执行一次循环再判断条件4.while循环语句while(expr){...}先判断条件再行一次循环5.for循环语句for循环是php中最复杂的循环结构。
for(expr1;expr2;expr3){...;}<?phpfor($i=1;$<=10;$i++){if($i==5) break;echo "循环".$i."<br>";}?>数组<?php$arr=array("id"=>2,"title"=>标题);//array定义一个变量数组$arr。
echo $arr[id];echo "<br>";$array=array(3,5,6,7);//array定义一个变量数组$array.print_r($array);//Array([0]=>3[1]=>5[2]=>6[3]=>7)echo "<br>";$arr1=array(array(3,6),array(2,4));//array定义一个二维数组.print_r($arr1);//Array([0]=>Array([0]=>3 [1]=>6)[1]=>Array([0]=>2[1]=>4)) echo "<br>";$arr2=array("视频","教程");//创建和修改数组。