I am writing a search form for my site and I cant seem to get it to work properly
I seen it to search the name or age or both and bring be back the results if say there are more than 5 then to bring them back on diffrent pages. this is what I have so far it works but I want to also have a submit all button insted of say just submits after each query.
please help
Terry
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">First Name: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">Age: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</form>
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">Birth Year: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</form>
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">Parish: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
include "mysql.class.php";
// Create a new mysql object
$mysqldb = new mysql("localhost","dbuser","password","db");
// Connect to the database server and select a database
$mysqldb->connect();
$mysqldb->select();
$pagesize = 2;
$term=$_POST['term'];
$recordstart = (isset($_GET['recordstart'])) ? $_GET['recordstart'] : 0;
$mysqldb->query("select * from ww1 where Name like '%$term%' LIMIT $recordstart,$pagesize");
// Output the result set
$actions = '<a href="http://jagosofcornwall.com/ww1/idVALUE.htm">View Detailed</a>';
echo $mysqldb->getResultAsTable($actions);
$mysqldb->query("select count(id) as count FROM ww1");
$row = $mysqldb->fetchObject();
$totalrows = $row->count;
// Create the 'previous' link
if ($recordstart > 0) {
$prev = $recordstart - $pagesize;
$url = $_SERVER['PHP_SELF']."?recordstart=$prev";
echo "<a href=\"$url\">Previous Page</a> ";
}
// Create the 'next' link
if ($totalrows > ($recordstart + $pagesize)) {
$next = $recordstart + $pagesize;
$url = $_SERVER['PHP_SELF']."?recordstart=$next";
echo "<a href=\"$url\">Next Page</a>";
}
$totalpages= ceil($totalrows / $pagesize);
$currentpage = ($recordstart / $pagesize ) + 1;
function pageLinks($totalpages, $currentpage, $pagesize,$parameter) {
// Start at page one
$page = 1;
// Start at record zero
$recordstart = 0;
// Initialize $pageLinks
$pageLinks = "";
while ($page <= $totalpages) {
// Link the page if it isn't the current one
if ($page != $currentpage) {
$pageLinks .= "<a href=\"".$_SERVER['PHP_SELF']."
?$parameter=$recordstart\">$page</a> ";
// If the current page, just list the number
} else {
$pageLinks .= "$page ";
}
// Move to the next record delimiter
$recordstart += $pagesize;
$page++;
}
return $pageLinks;
}
echo "<p>Pages: ".
pageLinks($totalpages,$currentpage,$pagesize,"recordstart").
"</p>";
?>
</body>
</html>
I seen it to search the name or age or both and bring be back the results if say there are more than 5 then to bring them back on diffrent pages. this is what I have so far it works but I want to also have a submit all button insted of say just submits after each query.
please help
Terry
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">First Name: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">Age: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</form>
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">Birth Year: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</form>
<form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
</font></p><p><font size="2" color="#ffffff">Parish: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
include "mysql.class.php";
// Create a new mysql object
$mysqldb = new mysql("localhost","dbuser","password","db");
// Connect to the database server and select a database
$mysqldb->connect();
$mysqldb->select();
$pagesize = 2;
$term=$_POST['term'];
$recordstart = (isset($_GET['recordstart'])) ? $_GET['recordstart'] : 0;
$mysqldb->query("select * from ww1 where Name like '%$term%' LIMIT $recordstart,$pagesize");
// Output the result set
$actions = '<a href="http://jagosofcornwall.com/ww1/idVALUE.htm">View Detailed</a>';
echo $mysqldb->getResultAsTable($actions);
$mysqldb->query("select count(id) as count FROM ww1");
$row = $mysqldb->fetchObject();
$totalrows = $row->count;
// Create the 'previous' link
if ($recordstart > 0) {
$prev = $recordstart - $pagesize;
$url = $_SERVER['PHP_SELF']."?recordstart=$prev";
echo "<a href=\"$url\">Previous Page</a> ";
}
// Create the 'next' link
if ($totalrows > ($recordstart + $pagesize)) {
$next = $recordstart + $pagesize;
$url = $_SERVER['PHP_SELF']."?recordstart=$next";
echo "<a href=\"$url\">Next Page</a>";
}
$totalpages= ceil($totalrows / $pagesize);
$currentpage = ($recordstart / $pagesize ) + 1;
function pageLinks($totalpages, $currentpage, $pagesize,$parameter) {
// Start at page one
$page = 1;
// Start at record zero
$recordstart = 0;
// Initialize $pageLinks
$pageLinks = "";
while ($page <= $totalpages) {
// Link the page if it isn't the current one
if ($page != $currentpage) {
$pageLinks .= "<a href=\"".$_SERVER['PHP_SELF']."
?$parameter=$recordstart\">$page</a> ";
// If the current page, just list the number
} else {
$pageLinks .= "$page ";
}
// Move to the next record delimiter
$recordstart += $pagesize;
$page++;
}
return $pageLinks;
}
echo "<p>Pages: ".
pageLinks($totalpages,$currentpage,$pagesize,"recordstart").
"</p>";
?>
</body>
</html>