View Full Version : Assistance with Previous and Next Record

06-14-2006, 08:30 PM
I have a form that query's a mysql database and populates a table with the query results. Each result has a link pointing to an invoice in the db. I can display the img just fine. The problem is that when i try to display the previous or next record it finds the next idnum in the squence. In other words, if the idnum is 102 the next record would be 103. but that is not correct. I need the previous and next records that are the result of the query. As and eample query pulls records of 102, 120, 121, 128, I need to see when next is clicked from 102, 120, then next again see 128 so fourth. Below is the code I have. Any Help will be greatly appreciated.


<form name = "result" form action = "final.php" method ="POST">

include ("conn1.php");


$result = $_POST['result'];
$idnum = $_POST['idnum'];
$ven= $_POST['ven'];
$imageid = $_POST['imageid'];

$sql = "
SELECT idnum, ven,veninvoice,kirkcheck,community,imageid
FROM corp
WHERE ven LIKE '%$ven%'
AND veninvoice LIKE '%$veninvoice%'
AND kirkcheck LIKE '%$kirkcheck%'
AND community LIKE '%$community%'
AND idnum LIKE '%$idnum%'
AND imageid LIKE '%$imageid%' order by 'idnum'

$result= mysql_query($sql) or die ("Can't connect");
$invoicetotal = mysql_num_rows($result);

echo "Total Invoices $invoicetotal";


<table border="0">


$j = 0;

$idnum = array();

while ($row = mysql_fetch_array($result)) {

echo ($j++%2==0) ? '<tr bgcolor="#FFFFCC">' : '<tr bgcolor="#FFFFFF">';
echo "<td>" .($row['ven']) . "</td>";
echo "<td>" .($row['veninvoice']) . "</td>";
echo "<td>" .($row['kirkcheck']) . "</td>";
echo "<td>" .($row['community']) . "</td>";

print '

<a href="final.php?idnum='.$row['idnum'].'">link</a>

echo '</table>';


*******************next page***************

<style type="text/css">
body { color: black; background: #ffffaa; }
<form name = "final" form action = "final.php" method ="POST">


include ("conn1.php");
echo $result;

if(is_array($_POST["idnum"])) {

$idnum = implode(",",$_POST["idnum"]);

$query = "SELECT * FROM corp WHERE idnum='$idnum'";
$result1 = mysql_query($query);
$row = mysql_fetch_row($result1);
$imageid = $row[5];

echo "<img src=$imageid.gif border = 4 align = right width=\"88%\">";

$previd = $idnum -1;
$nextid = $idnum +1;

echo "<a href =\"final.php?idnum=$nextid\">Next</a><BR>";
echo "<a href=\"final.php?idnum=$previd\">Previous</a><BR>";
echo "<a href =\"corpfind.php\">New Search</a><BR>";



06-14-2006, 09:41 PM
Any Thoughts?