Results 1 to 2 of 2

Thread: pass value to same page [Resolved]

Threaded View

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    pass value to same page [Resolved]

    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:

    PHP Code:
    //--- 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?
    Last edited by ober0330; Feb 19th, 2004 at 11:26 AM.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width