我有来自特定搜索按钮的格式。新生成的表单有几种形式,可以更新它自己的数据 如何进行这样的更新而不影响当前页面。 因搜索结果和搜索参数不应更改 最后问题排序,给我一个想法“在显示它的同时根据查询搜索更新每条记录”。
例如:
<pre>
**name:[** k% **] branch:[** acc **] SEARCH** >>>>search form
EMPID | NAME | BRANCH | EDIT |
1 | kamal | acc | edit | >>>>>>dynamicaly generated form based query serch
2 | kapila | acc | edit | >>>>>>dynamicaly generated form based query serch
</pre>
谢谢..
在这里我的尝试
<?php
session_start();
include("../../config/config.inc.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../../css/tbl.css"/>
<script type="text/javascript" src="../../jquery/formControll.js"></script>
<script type="text/javascript">
function autoSubmit(){
document.forms['searchForm'].action=SCRIPT_NAME;
document.forms['searchForm'].submit();
alert("done");
return true;
}
</script>
<title>OT Detail</title>
</head>
<body>
<?php
$errors = array();
$htmlcode="";
$me = $_SERVER['PHP_SELF'];
if(isset($_GET["invalid"])) //that means this is a redirected session
{
//form data default value initialization goes here
$Year=$_GET["Year"];
$Month=$_GET["Month"];
echo "<br><br><strong>ERROR: ";
foreach($_GET["errors"] as $k=>$v)
echo "<font color=red >".$v."</font>";
echo "</strong>";
}
else//if $_GET["invalid"] is not define then this is not redirecting session
{
//form data default value initialization goes here
$Year=date("Y");
$Month=date("m");
}
//for sequrity reasons we check weather 'REQUEST_METHOD'== 'POST'
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
//server side manual form validation goes here
if (!$_POST['Year'])
$errors[0] = "Year ?";
if (!$_POST['Month'])
$errors[1] = "Month?";
if (count($errors)>0){
header("Location:setOtPermit.php?invalid=1&Year=".$_POST["Year"]."&Month=".$_POST["Month"]."&errors=".$errors);
exit;
}
else //no error
{
//get post array
foreach($_POST as $key=>$value){
if ($key!="Search"){
$value=htmlentities(stripslashes(strip_tags($value)));
${$key}=$value;
}//if $key
}//4e
//******* building sql for search
$sql="SELECT branch FROM ".$tbl_name2." WHERE empNo=".$_SESSION['resideFigure'];
$result=mysql_query($sql,$con)or die("cannot query");
$row=mysql_fetch_array($result,MYSQL_NUM);
$myBranch="Finance";//$row[0];
//echo $myBranch;
$sql="select * from ".$tbl_name4." e
where e.empNo in(
select d.empNo
from ".$tbl_name2." d
where d.branch='".$myBranch."') and e.empNo=000123 and e.permitMonth=1";
//echo $sql;
$result=mysql_query($sql,$con)or die("cannot query");
//*** search result feching into table goes here
if(mysql_num_rows($result)>0)
{
$htmlcode.="<center><table id='myDisplay'>";
$htmlcode.="<tr>";
for($i = 0; $i < mysql_num_fields($result); $i++) {
$htmlcode.="<th>".mysql_field_name($result,$i)."</th>";
}//for mysql_num_fields
$htmlcode.="</tr>";
$rowAlter=true;
while($row = mysql_fetch_assoc($result))
{
$htmlcode.="<form name='myform[]' method='POST' action='".$me."' onSubmit='return validateForm()'>";
if($rowAlter)
{$htmlcode.="<tr>";
$rowAlter=false;
}
else
{
$htmlcode.="<tr class='alt'>";
$rowAlter=true;
}
foreach($row as $k=>$v)
{
$htmlcode.="<td><input type='text' name='mydata[]' value='".$v."'></td>";
}//4e
$htmlcode.="<td><input type='submit' name='Update' onclick='autoSubmit()' value='Update'></td></tr>";
}//while
$htmlcode.="</form></table></center>";
}
else//when data not fetched
{
echo "<br><br><font color=blue >It seems to be you have not done any OT Permission!</font>";
}
}//else error count
}//if $_SERVER
?>
<center><form name="searchForm" method="POST" action="<?php echo strip_tags($me);?>" onSubmit="return validateForm()">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td>Year</td><td><input type="text" name="Year" value="<?php echo $Year;?>"></td>
<td>Month</td><td><input type="text" name="Month" value="<?php echo $Month;?>"></td>
<td><input type="submit" name="Search" value="Search"></td>
<td><input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form></center>
<script type="text/javascript">SetHandlers()</script>
<?php
//display result as table
if (count($errors)==0)
echo $htmlcode;
//for sequrity reasons & confirm to dynamic form are submited we check weather 'REQUEST_METHOD'== 'POST'
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['Update'])){}
echo "if success i can do this its not difficult,but things is result desapper";
?>
</body>
</html>
答案 0 :(得分:1)
我想将信息发回同一页面。您可以使用php在脚本开头处理帖子,然后您已经拥有了所有提交的数据,这样您就可以使用该数据填充搜索字段和所有内容。
或者,不要提交表单,而是执行ajax查询。这样你的当前页面保持不变。