2017-06-29 84 views
0

輸入關鍵字時,數據不會被拉到我有搜索功能,我的設置。當我輸入關鍵字時,我沒有記錄回來,也沒有錯誤信息。只是表頭。我在數據庫中看到其他部門。當我在關鍵字框中輸入時,我什麼也收不回來。在搜索框中

<html> 
<head> 
<title></title> 
</head> 
<body> 
<form name="frmSearch" method="get" action=""> 
    <table width="599" border="1"> 
    <tr> 
     <th>Keyword 
     <input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>"> 
     <input type="submit" value="Search"></th> 
    </tr> 
    </table> 
</form> 
<?php 
if($_GET["txtKeyword"] != "") 
    { 
     $serverName = "localhost"; 
    $objConnect = new PDO("sqlsrv:server=$serverName ; Database=maintenance", "TestUser", "test") or die("Error Connect to Database"); 

    // Search By lanId or department 
    $objQuery = $objConnect->prepare("SELECT * FROM requests WHERE (lanId LIKE '%".$_GET["txtKeyword"]."%' or department LIKE '%".$_GET["txtKeyword"]."%') "); 

    ?> 
    <table width="600" border="1"> 
     <tr> 
     <th width="91"> <div align="center">lanId </div></th> 
     <th width="98"> <div align="center">Name </div></th> 
     <th width="198"> <div align="center">department </div></th> 

     </tr> 
    <?php 

     while($objResult = $objQuery->fetch(PDO::FETCH_ASSOC)) 
    { 
    ?> 
     <tr> 
     <td><div align="center"><?php echo $objResult["lanId"];?></div></td> 
     <td><?php echo $objResult["name"];?></td> 
     <td><?php echo $objResult["department"];?></td> 

    <?php 
    } 
    ?> 
    </table> 
    <?php 

} 
?> 
</body> 
</html> 
+0

您是否嘗試過類似的print_r($ objQuery->取(PDO :: FETCH_ASSOC));看看你是否真的在拉取數據? – hRdCoder

+0

只是去嘗試,沒有什麼快到了奇怪爲什麼 – Donny

+0

噢,對不起的,而不是調用取(),請嘗試使用fetchall()這樣的: 「的print_r($ objQuery->使用fetchall());」。 – hRdCoder

回答