I've checked out some sites to get examples of how to implement Next and Prev buttons to my website but I seem to be having come problem with it. Could you please take a look at the code below and tell me what I have done wrong?
Code: Select all
// Receiving input from user
// Searchword
$searchword = $_GETї'searchword'];
print "Your word(s) is/are: <b>$searchword</b><p>\n\n";
// Checking the total number of findings
if (! empty($searchword )){
$query = "SELECT diagram FROM arguments WHERE aml LIKE '%$searchword%'";
$result1 = mysql_query($query)
or die ("Query failed");
$max = 0;
// Determine the number of items containing the $searchword
while ($line1 = mysql_fetch_array($result1)){
$max++;
}
// Display the findings
print "<center>Database Search returned $max items containing "<i>$searchword</i>".</center>";
// Free resources
mysql_free_result( $result1 );
}
// The number of results to be displayed on screen
$maxresult = 2;
// Searching by keyword
// Using user's input -> Note that will only search specific word(s),
// i.e. 'chinese' will have a set of results and 'chinese brown' will have a different set of
// results, plus 'brown' will have a 3rd different result
if (! empty($searchword )){
$query = "SELECT aml FROM arguments WHERE aml LIKE '%$searchword%'";
$result2 = mysql_query($query)
or die ("Query failed");
// When the current page is yet to be determined
if (!$page) {
$page = 1;
}
// Set up
$backpage = $page - 1;
$nextpage = $page + 1;
if (empty($start)){
$start = 0;
}
else {
$start = ($maxresult * $page) - $maxresult;
}
$num_rows = mysql_num_rows($result2);
// When the query returns less or equal number of rows than the limit set by $maxresult
if ($num_rows <= $maxresult) {
$num_pages = 1;
}
// When the query returns the exact limit set by $maxresult
else if (($num_rows % $maxresult) == 0) {
$num_pages = ($num_rows / $maxresult);
}
// For any other cases...
else {
$num_pages = ($num_rows / $maxresult) + 1;
}
// Declared as an integer
$num_pages = (int) $num_pages;
// The current page is greater than the total number of pages or
// the current page is less than 0
if (($page > $num_pages) || ($page < 0)) {
error("You have specified an invalid page number");
}
// Set the limit per page
$query = $query . " LIMIT $start, $maxresult";
$result2 = mysql_query($query);
// The navigation between pages
// Ensure only display when total number of return results exceeds $maxresult
// i.e. will not display if only 1 page
if ($max>$maxresult){
print "<center>- ";
if ($backpage) {
print "<a href="$PHP_SELF?searchword=$searchword&page=$backpage">Prev</a>";
}
// If its the first page; have 'Prev' un-clickable
else {
print "Prev";
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $page) {
print " <a href="$PHP_SELF?searchword=$searchword&page=$i">$i</a> ";
}
else {
print " $i ";
}
}
if ($page != $num_pages) {
print "<a href="$PHP_SELF?searchword=$searchword&page=$nextpage">Next</a> -";
}
else {
print "Next -";
}
print "</center>";
}
print "<table border="10"><th BGCOLOR="#ff0000">Results</th>";
while ($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) {
print "\t<tr BGCOLOR="#ccffff">\n";
// The different color, in this case aqua
foreach ($line2 as $col_value) {
// Make into string
$xml = join($line2,'');
// Set up strings
$search = '<!DOCTYPE ARG SYSTEM "argument.dtd">';
// Replacement operation
$new_xml = str_replace( $search, "", $xml);
// Create an array
$arguments = array('/_xml'=> $new_xml);
$xsl = "sheet1.xsl";
// Create an XSLT processor
$xslthandler = xslt_create();
// Perform the transformation
$html = xslt_process($xslthandler, 'arg:/_xml', $xsl, NULL, $arguments);
// Detect errors
if (!$html) die ('XSLT processing error: '.xslt_error($xslthandler));
// Destroy the XSLT processor
xslt_free($xslthandler);
// Output the resulting HTML
print "\t\t<td><pre>$html</pre></td>\n";
}
print "\t</tr>\n";
}
// Free resources
mysql_free_result( $result2 );
}
if (empty($searchword )){
print "<h1><center><font color='#000080'>You have not entered text to be searched!</center><hl>";
}
// Closing connection
mysql_close( $link );Thanks you.
Chia