php - Show database entries after pressing submit button
I have a page where I search for the books that an author wrote (really basic search based on an assignment I had 2 months ago). I choose the author from a dropdown box and after I press the "Submit" button the results should appear.
Here is the page's code:
<?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 class="page_speed_484497515"><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>
As you can see I have everything inside a table (convenient for small stuff like this). I want when I press the submit button, the author that was chosen to be inputed in a method which will display the results from the query. The query will be executed in theforeach
where the ?????? are. Then I want the result of the query to be used to display inside my table (by adding more rows and inserting one result in each row through a php function) the results.
Is there a way to do that just with php? I don't know how to use Javascript just php and html. Even if I have to insert the result of the query in another page and display everything there I'm ok with that.
I haven't written the query just yet.
Actually the foreach is there to put in a single variable each book the author has written.
Answer
Solution:
Here's an example. Queries/fields are bogus.