php

jagosof

New Member
Messages
4
Reaction score
0
Points
0
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>
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
If I understand you correctly, you want the user to press 'submit' once and then it will query the database once, but you want the results to be displayed 5 at a time?

I think what you have now, with multiple queries, is the best way to go, though you can use the php serialize function to save every row and then use sessions, cookies, etc to pass the results along. If you just want to hide the submit button, you can use javascript:
Code:
SCRIPT language="JavaScript">
function submitform()
{
  document.myform.submit(); //myform is the name of your form
}
</SCRIPT>
and you can use anything you want to submit the form:
Code:
<a href="javascript:submitform()">next</a>

I hope this is what you're asking :)
 

jagosof

New Member
Messages
4
Reaction score
0
Points
0
Thank you for your reply, I have put that into play but its not quite want I want. I would like what you suggested too where someone can either submit one query with say name or type in name age address and then submit. I cant work out how to use just one submit button. :(
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Better would be to use a single form and have your form handler construct the WHERE clause based on which input fields are set.

And don't forget to sanitize user input with (e.g.) mysql_real_escape_string or the filter functions to prevent SQL injection.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
@jagosof
try to use the CODE or the PHP tags next time
 
Top