标签:
( 书号, 类别, 书名, 出版社, 年份, 作者, 价格, 总藏书量, 库存 )
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> <?php echo "<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; } ?>
<input type="submit" value="执行" style="width:50px; height:25px; margin:0px 250px;" onclick="javascript:this.form.action='deleteCard.php';">5.不足之处
标签:
原文地址:http://blog.csdn.net/u013224148/article/details/46493403