This is back to a project I was asking questions about earlier. I'm traversing through records. The page displays one record at a time (~20 fields) and I have a "Next" and "Previous" button. If they are on the first record that is returned by the query, and they hit the "Previous" button, I want to show the last record according to the query.
I had this all working and it walked through the table one after another, but now I've added a search function and I'm using 1 variable and a loop to find which record I should be on next.
The current code, if it helps (I haven't added any special-case checks to the Previous ("last") part):
PHP Code:if(isset($_GET['numid']))
{
$loopnum = $_GET['numid'];
switch($_GET['dir'])
{
//----------------Start at first record----------------------------------------------
//---------------------------------------------------------------------------------------
case "first":
$row = mssql_fetch_array($result2);
$id = $row[0];
$loopnum++;
break;
//----------------Go forward one record----------------------------------------------
//---------------------------------------------------------------------------------------
case "next":
if($_GET['numid'] == "-1")
{
$row = mssql_fetch_array($result2);
$row = mssql_fetch_array($result2);
$loopnum = 1;
}
else
{
while(($row = mssql_fetch_array($result2)) && ($i != $_GET['numid']))
{
$i++;
}
$loopnum++;
}
$id = $row[0];
break;
//----------------Go back one record----------------------------------------------
//---------------------------------------------------------------------------------------
case "last":
while(($row = mssql_fetch_array($result2)) && ($i < $_GET['numid']))
{
$i++;
}
$id = $row[0];
$loopnum--;
break;
}// end of switch
}// end else for isset of ID




Reply With Quote