標籤:
1.圖書的查詢a.要求可以對書的 類別, 書名, 出版社, 年份(年份區間), 作者, 價格(區間) 進行查詢. 每條圖書資訊包括以下內容:
( 書號, 類別, 書名, 出版社, 年份, 作者, 價格, 總藏書量, 庫存 )
b.可選要求: 可以按使用者指定屬性對圖書資訊進行排序. (預設是書名)
這裡遇到的最大的問題就是漢字的排序問題 由於錯在中文 首先編碼就是一個問題 一般我們會使用國際通用的
編碼方式 UTF-8 ,但是使用這個進行排序的時候結果並不理想 如果使用GBK編碼格式的話,得到的結果還是
比較理想的
但是如果改變一個資料庫的編碼格式又會帶來不可預料的結果 所以嘗試找一些折中的辦法試一下
網上找了各種辦法 我照著做了但是似乎並沒有什麼卵用 點擊開啟連結
<style type="text/css">table.hovertable {font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #999999;border-collapse: collapse;margin:20px 250px;width:800px;padding: 0px 0px;}table.hovertable th {background-color:#c3dde0;border-width: 1px;padding: 8px;border-style: solid;border-color: #a9c6c9;}table.hovertable tr {background-color:#d4e3e5;}table.hovertable td {border-width: 1px;padding: 8px;border-style: solid;border-color: #a9c6c9;}</style><?phpecho "<h1 style='text-align:center; margin:20px 0px;'><font color='#50b3ed'>圖書查詢結果</font></h1>";echo "<a style='margin:0px 900px; width:50px;' href='searchBook.php'><font color='#1111e8'>Return</font></a>";require("MySqlUtils.php");header("Content-type:text/html;charset=utf-8");$bookID = $_POST['bookNumber'];$classfication = $_POST['bookClass'];$bookName = $_POST['bookName'];$press = $_POST['press'];$publicTime = $_POST['date'];$author = $_POST['author'];$price = $_POST['price'];$numberAll = $_POST['number'];$numberNow = $_POST['numberNow'];$orderBy = $_POST['orderBy'];$PublicTimeEnd = $_POST['dateEnd'];$priceHight = $_POST['priceHight'];$numberAllHigth = $_POST['numberHight'];$numberNowHight = $_POST['numberNowHight'];changeClassfication();checkForm();$sql = "select * from book where";$isFirstNotNull = true;if ($bookID){$isFirstNotNull = false;$sql = $sql." BookID like ".$bookID."%";}if ($classfication){if ($isFirstNotNull){$sql = $sql." Classification = '".$classfication."'";}else{$sql = $sql." and Classification = '".$classfication."'";}$isFirstNotNull = false;}if ($bookName){if ($isFirstNotNull){$sql = $sql." BookName like '%".$bookName."%'";}else{$sql = $sql." and BookName like '%".$bookName."%'";}$isFirstNotNull = false;}if ($press){if ($isFirstNotNull){$sql = $sql." Press like '%".$press."%'";}else{$sql = $sql." and Press like '%".$press."%'";}$isFirstNotNull = false;}if ($publicTime){if (!$PublicTimeEnd){if ($isFirstNotNull){$sql = $sql." PublicTime = '".$publicTime."'";}else{$sql = $sql." and PublicTime = '".$publicTime."'";}}else{if ($isFirstNotNull){$sql = $sql." PublicTime between '".$publicTime."' and '".$PublicTimeEnd."'";}else{$sql = $sql." and PublicTime between '".$publicTime."' and '".$PublicTimeEnd."'";}}$isFirstNotNull = false;}if ($author){if ($isFirstNotNull){$sql = $sql." Author like '%".$author."%'";}else{$sql = $sql." and Author like '%".$author."%'";}$isFirstNotNull = false;}if ($price){if (!$priceHight){if ($isFirstNotNull){$sql = $sql." Price = '".$price."'";}else{$sql = $sql." and Price = '".$price."'";}}else{if ($isFirstNotNull){$sql = $sql." Price between '".$price."' and '".$priceHight."'";}else{$sql = $sql." and Price between '".$price."' and '".$priceHight."'";}}$isFirstNotNull = false;}if ($numberAll){if (!$numberAllHigth){if ($isFirstNotNull){$sql = $sql." NumberAll = '".$numberAll."'";}else{$sql = $sql." and NumberAll = '".$numberAll."'";}}else{if ($isFirstNotNull){$sql = $sql." NumberAll bewteen '".$numberAll."' and '".$numberAllHigth."'";}else{$sql = $sql." and NumberAll bewteen '".$numberAll."' and '".$numberAllHigth."'";}}$isFirstNotNull = false;}if ($numberNow){if (!$numberNowHight){if ($isFirstNotNull){$sql = $sql." StoreNumber = '".$numberNow."'";}else{$sql = $sql." and StoreNumber = '".$numberNow."'";}}else{if ($isFirstNotNull){$sql = $sql." StoreNumber between '".$numberNow."' and '".$numberNowHight."'";}else{$sql = $sql." and StoreNumber between '".$numberNow."' and '".$numberNowHight."'";}}$isFirstNotNull = false;}if ($isFirstNotNull){$sql = "select * from book";}$sql = $sql." order by ".$orderBy;//." CONVERT( name USING gbk ) COLLATE gbk_chinese_ci ASC";//echo $sql;$link = getLink();if($link){$resoures = getResoures('libray', $sql);if(!$resoures){echo "<Script>alert('查詢失敗 請檢查查詢設定或者聯絡系統管理員!');</Script>";echo "<Script>window.location.href='searchBook.php'</Script>";}$info = mysql_fetch_array($resoures);if(!$info){echo "<Script>alert('查詢結果為空白 請修改查詢條件!');</Script>";}$countBook = 1;echo "<table class='hovertable'>";echo "<tr><th>數目</th> <th>書號</th> <th>類別</th> <th>書名</th> <th>出版社</th> <th>年份</th> <th>作者</th> <th>價格</th> <th>總藏書數量</th> <th>庫存量</th> </tr>";while($info){echo "<tr> <th>$countBook</th> <th>$info[BookID]</th> <th>$info[Classification]</th> <th>$info[BookName]</th> <th>$info[Press]</th> <th>$info[PublicTime]</th> <th>$info[Author]</th> <th>$info[Price]</th> <th>$info[NumberAll]</th> <th>$info[StoreNumber]</th> </tr>";$countBook++;$info = mysql_fetch_array($resoures);}echo "</table>";closeConnect($link);}else{echo "資料庫連接失敗";}function changeClassfication(){global $classfication;if(1 == $classfication){$classfication = '人文';}else if(2 == $classfication){$classfication = '教輔';}else if(3 == $classfication){$classfication = '科技';}else if(4 == $classfication){$classfication = '遊戲';}else if(5 == $classfication){$classfication = '生活';}else if(6 == $classfication){$classfication = '技術';}else if(7 == $classfication){$classfication = 'IT';}}function checkForm(){//下面是對圖書編號的合法性進行檢測global $bookID;$isRightBookID = preg_match('/[0-9]/', $bookID);if (!$isRightBookID && $bookID){echo "<Script>alert('圖書編號含有非法字元')</Script>";echo "<Script>window.location.href='searchBook.php'</Script>";return false;}//價格global $price;$isRightPrice = preg_match('/[0-9]./', $price);if (!$isRightPrice && $price){echo "<Script>alert('圖書價格含有非法字元')</Script>";echo "<Script>window.location.href='searchBook.php'</Script>";return false;}//庫存global $numberAll;$isRightAllNumber = preg_match('/[0-9]/', $numberAll);if (!$isRightAllNumber && $numberAll){echo "<Script>alert('圖書庫存含有非法字元')</Script>";echo "<Script>window.location.href='searchBook.php'</Script>";return false;}global $numberNow;$isRightNowNumber = preg_match('/[0-9]/', $numberNow);if (!$isRightNowNumber && $numberNow){echo "<Script>alert('圖書庫存含有非法字元')</Script>";echo "<Script>window.location.href='searchBook.php'</Script>";return false;}return true;}?>
2.其他功能實現簡介對於管理員 還有借閱歸還圖書和借書證管理的功能 實現方法大同小異對於使用者來說,只有查詢書籍和修改自己密碼的功能 初始密碼是123456 密碼都是經過MD5加密後來儲存的
3.總結主要使用到的技術點:1. PHPExcel的使用這個開源的工具十分強大 不僅僅能夠讀取一個excel 而且可以建立一個excel表 最最關鍵的是可以在建立的時候設定好多的屬性詳細的使用方法可以參考這裡2.MySql的使用通過php來和背景資料庫MySql進行資料的互動 這裡我主要是使用了MySql提供的一系列函數類似於JDBC和ODBC 但是似乎更簡單 封裝更好使用方法參考這裡3.php資料互動方式一般都是通過表單進行一個資料的提交 可以指定是POST還是Get方法 通過php定義的全域數組來擷取這個資料,此外cookie session也可以這樣擷取 可以說非常之簡單4.一個表單提交到不同的頁面這個很簡單其實 就是利用javascript指令碼 在sublim上加上一個點擊事件 然後在觸發這個點擊事件的時候我們改變這個表單的action屬性就好了
<input type="submit" value="執行" style="width:50px;height:25px; margin:0px 250px;"onclick="javascript:this.form.action='deleteCard.php';">
5.不足之處 寫的緊 代碼淩亂 一些設計不到位 這個其實是自己的水平不到異常處理可能存在問題 對於很小的資料量應該沒問題 大量的訪問必然會出問題
暫時這個多 代碼貼出 完善時會繼續更新
php+MySQL圖書管理系統(四)