Hi All,
Hoping someone can help me out here. I've googled loads and consulted a reference textbook and now I'm pulling my hair out.
I'm designing a web-based front-end for a customer's database and have hit a snag whilst implementing a required feature from the client.
I have a database of 14000+ records to work with, and the essential idea is that you search the database to list only the relevant results. You then click the desired result from the list to display company information, such as address, which products they produce etc.
This part is fine, however once you're viewing a record (on a page called viewrecord.php), my client requires that you can have buttons to navigate through the result set. e.g. Click > to see the next record (company, product, address info on the viewrecord.php page) returned from the original search. Click << to see the first result returned from the search... etc. This is much like an Ms Access form I suppose.
I've searched everywhere to see how to implement this, however all the seemingly relevant google results point to how to implement pagination. i.e. view 10 list results at a time with buttons for previous 10 and next 10.
If anyone had any hints as to how to achieve this, then I would be most grateful. I'm thinking it may involve a temporary table, but with php, once the script executes, the temporary table is apparantly destroyed.
Many Thanks in advance.
Edit
For those interested, I solved the issue partly. Just need to ensure the 'Next' link can be made not a hyperlink once you reach the end of the recordset.
Any feedback on this code would be appreciated. Thanks.
Hoping someone can help me out here. I've googled loads and consulted a reference textbook and now I'm pulling my hair out.
I'm designing a web-based front-end for a customer's database and have hit a snag whilst implementing a required feature from the client.
I have a database of 14000+ records to work with, and the essential idea is that you search the database to list only the relevant results. You then click the desired result from the list to display company information, such as address, which products they produce etc.
This part is fine, however once you're viewing a record (on a page called viewrecord.php), my client requires that you can have buttons to navigate through the result set. e.g. Click > to see the next record (company, product, address info on the viewrecord.php page) returned from the original search. Click << to see the first result returned from the search... etc. This is much like an Ms Access form I suppose.
I've searched everywhere to see how to implement this, however all the seemingly relevant google results point to how to implement pagination. i.e. view 10 list results at a time with buttons for previous 10 and next 10.
If anyone had any hints as to how to achieve this, then I would be most grateful. I'm thinking it may involve a temporary table, but with php, once the script executes, the temporary table is apparantly destroyed.
Many Thanks in advance.
Edit
For those interested, I solved the issue partly. Just need to ensure the 'Next' link can be made not a hyperlink once you reach the end of the recordset.
Any feedback on this code would be appreciated. Thanks.
Code:
<?php
mysql_connect("xxx","xxx","xxx");
mysql_select_db("xxx");
// define record that you want to view from tempid in list page
$currentrecord = $_GET['tempid'];
$currentrecord -= 1;
$previousrecord = $currentrecord;
$nextrecord = $currentrecord + 2;
// get list of records from the created list
$sqlresults = "SELECT @rownum:=@rownum+1 'tempid', p.* from companies p, (SELECT @rownum:=0) r ORDER BY companyname ASC";
$searchresult = mysql_query($sqlresults) or die('Could not Connect: ' . mysql_error());
mysql_data_seek($searchresult,$currentrecord);
$searchcountrows = mysql_num_rows($searchresult);
$row = mysql_fetch_row($searchresult);
$num = mysql_num_rows($searchresult);
?>
<!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>View Record</title>
</head>
<body>
<?
echo $row[3];
echo "<br><br>";
if ($previousrecord <= 0) {
echo "Previous - <a href=\"testrecord.php?tempid=$nextrecord\">Next</a>";
} else {
echo "<a href=\"testrecord.php?tempid=$previousrecord\">Previous</a> - <a href=\"testrecord.php?tempid=$nextrecord\">Next</a>";
}
?>
</body>
</html>