SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get previous and next record to change html table

    Hello again,

    I am trying to find away to query my db for all the possible types of shipping packages per product and then display a table of prices based on the current package. After all that I want to be able to to have the user click on a button to go to the next package type and repopulate the html table (I also would like to allow for navigating to the previous record if there is one)
    something like:
    Price1 $5.75
    Price2 $5.25
    Price3 $5.25 << >>
    Price4 $2.05 currentpackage type

    This all comes from one table name productpackaging so I think it should be pretty easy but I am stuck particularly with the navigation through the records.

    Any Help??

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Pass the current value in the form or URL so that you can select rows that are greater or less than that value. ORDER BY and LIMIT provide the seeking through the table.

  3. #3
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so if I am understanding correctly - I need a variable for the current value
    $current = $_GET[PackageId]

    then a query that is ORDER BY PackageId and has a LIMIT 1

    But how do I provide the seeking through the table?

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think seeking means package='$curentid'. I dont know how much i understand.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Zealot samohtwerdna's Avatar
    Join Date
    Jul 2007
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what if I set up the function like so:

    PHP Code:
    <?php
                        
    function get_packages($pid)
                            {
                              
    $ProductId $pid;
                              
    $sql mysql_query("SELECT DISTINCT pdp.PackageId, PackageType FROM productpackaging pdp, packaging p WHERE pdp.ProductId = $ProductId AND pdp.PackageId = p.PackageId");
                            
                              while(
    $row mysql_fetch_assoc($sql))
                              {
                                
    $rows[] = $row;
                              }
                            
                              return 
    $rows;
                            }
                        
    $currentPackage $_GET['PackageID'];
                        
                        
    // don't forget to validate the packageID
                        
                        
    $packages get_packages($ProductId);
                        
                        
    $prevLink false;
                        
    $clink false;
                        
    $nextLink false;
                        
                        for(
    $i 0$i count($packages); $i++)
                        {
                          if(
    $packages[$i]['PackageID'] == $currentPackage)
                          {
                            
    // check for previous link
                        
                            
    if($i != 0)
                            {
                              
    $prevLink = ($i 1);
                              
    $clink = ($i);
                            }
                        
                            
    // check for next link
                        
                            
    if($i != (count($packages) - 1))
                            {
                              
    $nextLink = ($i 1);
                              
    $clink = ($i);
                            }
                        
                            
    // done, stop searching
                        
                            
    break;
                          }
                        }
                                            
    mysql_free_result($result);
                        
    ?>

                            <td><?php             // previous link
                        
                        
    if($prevLink)
                        {
                          echo 
    '<button onclick="" ><<</button>';
                        }
                        
                        
    // nextlink
                        
                        
    if($nextLink)
                        {
                          echo 
    '<button onclick="" >>></button>';
                        } 
    ?></td>
                          </tr><?php
                        
                        ?>
                          <tr>
                            <td><div align="center" style="font-size:smaller;"><?php echo $packages[$clink]['PackageType']; ?></div></td>
    Can I set up the button onclick event to go to the previous and next record?

    Ultimately I would like to use the button to change a variable for the PackageId so I can display my table of prices differently for each PackageId


Bookmarks

Posting Permissions

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