我有一个表格,最初在页面加载时被填满。现在,我有一个搜索按钮来过滤表格,我有发布功能来过滤搜索结果,但每次我通过文本框搜索时它都会加载,这不是好。每次搜索网格时,我都需要一个 ajax 或 J 子或 JavaScript 代码来加载网格。
我的桌子:
<table align="center" class="sortable" border="1" width="900px">
<tr >
<td class="sorttable_nosort" style=" font-weight:bold; text-align:center">Select</td>
<td class="sorttable_nosort" style=" font-weight:bold; text-align:center">Action</td>
<td style=" font-weight:bold;">Product Code</td>
<td style=" font-weight:bold;">Warranty Periods In Months</td>
<td style=" font-weight:bold;">ProRata Period In Months </td>
<td style=" font-weight:bold;">Manufacturer Date</td>
<td style=" font-weight:bold;">Applicable Form Date</td></tr>
<?php
// This while will loop through all of the records as long as there is another record left.
while( $record = mysql_fetch_array($query))
{ // Basically as long as $record isn't false, we'll keep looping.
// You'll see below here the short hand for echoing php strings.
// <?=$record[key] - will display the value for that array.
?>
<tr>
<td bgcolor="#FFFFFF" style=" font-weight:bold; text-align:center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $record['ProductCode']."~".$record['ManufactureDate']; ?>"></td>
<td bgcolor="#FFFFFF" style=" font-weight:bold; text-align:center"> <a style="color:#FF2222" name="edit" href="productwarrantymaster.php?<?php if(($row['editrights'])=='Yes') { echo 'ProductCode='; echo $record['ProductCode'];echo '&ManufactureDate=';echo $record['ManufactureDate'];} else echo 'permiss'; ?>">Edit</a></td>
<td bgcolor="#FFFFFF"><?=$record['ProductCode']?> </td>
<td bgcolor="#FFFFFF" ><?=$record['WarrantyPeriod']?></td>
<td bgcolor="#FFFFFF"> <?=$record['ProRataPeriod']?> </td>
<td bgcolor="#FFFFFF" > <?=$record['ManufactureDate']?> </td>
<td bgcolor="#FFFFFF" > <?=$record['ApplicableFormDate']?> </td></tr>
<?php
}
?>
</table>
我也使用了分页代码来填充这里也添加的网格。
我的 POST 功能:
if(isset($_POST['Search']))
{
if(isset($_POST['codes'])||isset($_POST['names']))
{
if(empty($_POST['codes'])&&empty($_POST['names']))
{
?>
<script type="text/javascript">
alert("Enter text Field!!");document.location='productwarrantymaster.php';
</script>
<?
}
else
{
if(!empty($_POST['codes'])&&!empty($_POST['names']))
{
$condition="SELECT * FROM productwarranty WHERE ProductCode like'%".$_POST['codes']."%' AND ManufactureDate like'".
$_POST['names']."%'";
}
else if(!empty($_POST['codes'])&&empty($_POST['names']))
{
$condition="SELECT * FROM productwarranty WHERE ProductCode like'%".$_POST['codes']."%'";
}
else if(!empty($_POST['names'])&&empty($_POST['codes']))
{
$condition="SELECT * FROM productwarranty WHERE ManufactureDate like'".$_POST['names']."%'";
}
else
{
$condition="SELECT * FROM productwarranty WHERE 1";
}
$refer=mysql_query($condition);
$myrow1 = mysql_num_rows($refer);
//mysql_fetch_array($query);
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 10;
$startpoint = ($page * $limit) - $limit;
//to make pagination
$statement = "productwarranty";
//show records
$starvalue = $myrow1;
$query = mysql_query("{$condition} LIMIT {$startpoint} , {$limit}");
if($myrow1==0)
{
?>
<script type="text/javascript">
alert("Entered keyword not found!!");document.location='productwarrantymaster.php';
</script>
<?
}
}
}
}
我的搜索表:
<div style="width:80px; height:30px; float:left; margin-left:3px; margin-top:16px;" >
<label>Product Code</label>
</div>
<div style="width:145px; height:30px; float:left; margin-left:3px; margin-top:16px;">
<input type="text" name="codes" value=""/>
</div>
<!--Row1 end-->
<!--Row2 -->
<div style="width:80px; height:30px; float:left; margin-left:3px; margin-top:9px;">
<label>Manufacturer Date</label>
</div>
<div style="width:145px; height:30px; float:left; margin-left:3px; margin-top:16px;" >
<input type="text" id="searchdate" name="names" value=""/>
</div>
<!--Row2 end-->
<div style="width:83px; height:32px; float:left; margin-top:16px;">
<input type="submit" name="Search" value="" class="button1"/>
</div>
请帮我解决这个问题。提前致谢:P