PDA

Click to See Complete Forum and Search --> : pass value to same page [Resolved]


ober0330
Feb 19th, 2004, 07:01 AM
I have a php file that displays one record at a time (approximately 30 values). I also have a "next" and "previous" button which, when clicked, will grab the next record and redisplay the page.

To navigate through these records, I'm going to the next and previous ID field (an identity column in the table of the DB). However, when the users tries to navigate to another record, I need to pass the current ID value that I'm on back into the same page.

I was thinking of using a hidden text box and submitting it using a form method, but I have 2 submit buttons!

Here is the code I use to get the proper ID value if it helps:


//--- get the maximum id ---------
$maxid=0;
$query2 = "SELECT MAX(ID) FROM Vendor";
$result2 = mssql_query($query2);
$row2 = mssql_fetch_array($result2);
$maxid=$row2[0];
//-----------------------------

switch($_GET['dir'])
{
//----------------Start at first record----------------------------------------------
//---------------------------------------------------------------------------------------
case "first":
// ---- on entry, start at first record in DB
$id=0;
//--- do not break in case the first record is not "1"

//----------------Go forward one record----------------------------------------------
//---------------------------------------------------------------------------------------
case "next":

$go=0;
while($go<1)
{
// --- grab the next valid id
$id++;
if($id > $maxid)
{
$id=0;
}
else
{
$query2 = "SELECT COMP_NAME FROM Vendor WHERE ID = " . $id;
$result2 = mssql_query($query2);
$row2 = mssql_fetch_array($result2);
if($row2[0] != "")
$go=1;
}
}
break;

//----------------Go back one record----------------------------------------------
//---------------------------------------------------------------------------------------
case "last":

$go=0;
while($go<1)
{
$id--;
if($id==0)
{
// --- if at the first record and trying to go back,
// --- go to the last record
$id=$maxid;
}
else
{
// --- grab previous record id
$query2 = "SELECT COMP_NAME FROM Vendor WHERE ID = " . $id;
$result2 = mssql_query($query2);
$row2 = mssql_fetch_array($result2);
if($row2[0] != "")
$go=1;
}
}
break;
}

Can someone help me?

ober0330
Feb 19th, 2004, 10:26 AM
I solved this. All I did was stuff the new ID value into a link that contained a GET string. This can then be pulled from the GET array and used to move between records.