Php 按“提交”按钮后显示数据库条目
我有一个页面,在那里我搜索一位作者写的书(实际上是基于我两个月前的作业进行的基本搜索)。我从下拉框中选择作者,按下“提交”按钮后,结果应该会出现 以下是页面的代码:Php 按“提交”按钮后显示数据库条目,php,mysql,html-table,Php,Mysql,Html Table,我有一个页面,在那里我搜索一位作者写的书(实际上是基于我两个月前的作业进行的基本搜索)。我从下拉框中选择作者,按下“提交”按钮后,结果应该会出现 以下是页面的代码: <?php include ("includes/connections.php"); if($_POST) { if (!isset($_POST["authors"])){ header("Location: searchAuthor.php"); exit;
<?php
include ("includes/connections.php");
if($_POST)
{
if (!isset($_POST["authors"])){
header("Location: searchAuthor.php");
exit;
}
foreach ($_POST["authors"] as $author)
{
?????????
}
}
?>
<?php include ("includes/connections.php");
function dropdown($intIdField, $strfNameField, $strlNameField, $strTableName, $strOrderField, $strNameOrdinal, $strMethod="asc") {
echo "<select name=\"{$strNameOrdinal}[]\">\n";
echo "<option value=\"NULL\">Select Value</option>\n";
$strQuery = "SELECT $intIdField, $strfNameField, $strlNameField
FROM $strTableName
ORDER BY $strOrderField $strMethod";
$rsrcResult = mysql_query($strQuery) or die(mysql_error());
while($arrayRow = mysql_fetch_assoc($rsrcResult)) {
$strA = $arrayRow["$intIdField"];
$strB = $arrayRow["$strlNameField"] . " " . $arrayRow["$strfNameField"];
echo "<option value=\"$strA\">$strB</option>\n";
}
echo "</select>";
}
?>
<!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=utf-8" />
<title>Add Book Information</title>
<link href="back.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Search for Books of an Author</h1><table width="528" border="0" align="center">
<tr>
<td width="480"><span id="tip">*Hitting the "Search books of Author" button without filling the fields with an asterisk will just reset the form</span></td>
</tr>
</table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" id="formBook">
<table width="563" border="0" align="center">
<tr>
<td style="text-align: right"><label for="authors">Select an Author*:</label></td>
<td><?php dropdown("author_ID", "author_firstname", "author_lastname", "author", "author_lastname", "authors"); ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Search books of Author" /></td>
</tr>
<tr>
<td><div align="left"><img src="images/buttonleft.png" alt="previous" width="70" height="70" usemap="#Previous" border="0"></div></td>
<td><div align="right"><img src="images/buttonright.png" alt="next" width="70" height="70" usemap="#Next" border="0">
<map name="Previous">
<area shape="circle" coords="35,35,33" href="addSubject.php">
</map>
<map name="Next">
<area shape="circle" coords="35,35,33" href="addEdition.php">
</map>
</div></td>
</tr>
</table>
</form>
</body>
</html>
添加图书信息
寻找作者的书
*点击“搜索作者书籍”按钮而不在字段中填入星号,只会重置表单
这里有一个例子。查询/字段是伪造的
<?php
if (isset($_POST['Submit'])) {
$strQuery = "SELECT 'field1', 'field2', 'field3'
FROM $strTableName
ORDER BY $strOrderField $strMethod";
$rsrcResult = mysql_query($strQuery) or die(mysql_error());
?>
<table>
<td> HEADER 1 </td> <td> HEADER 2 </td> <td> HEADER 3 </td>
<?php
while ($row = mysql_fetch_array($rsrcResult) {
echo "<tr><td>".$row['field1']."</td><td>".$row['field2']."</td><td>".$row['field3']."</td>";
}
?>
</table>
我知道怎么做,我的问题是如何在另一个php函数中传递查询结果我不明白为什么首先需要一个函数我只是担心变量$rsrcResult
是否会全局使用它,以便在while循环中使用它?