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>
您是否尝试过类似的print_r($ objQuery->取(PDO :: FETCH_ASSOC));看看你是否真的在拉取数据? – hRdCoder
只是去尝试,没有什么快到了奇怪为什么 – Donny
噢,对不起的,而不是调用取(),请尝试使用fetchall()这样的: “的print_r($ objQuery->使用fetchall());”。 – hRdCoder