L
lscruiser

  • Dec 23, 2009
  • Joined Nov 2, 2009
  • Thank you for your reply. Table A is a view that holds many columns of information about the fname and lname (the employee). I can't change this database and table.
    Table B holds different information about fname and lname (the employee) which is selected by the user and viewed by all on a web page. The WHERE statement includes only current employees from Table A. Table B's information can be updated and deleted by a sub-admin. The fname and lname's are populated by a drop down from Table A and when submitted is matched with new information that was selected by the user in Table B. I choose a drop down to protect data integrity.
    Are you saying that the fname and lname should always come from Table A even though it is matched with new information in Table B? Then Table B would match an ID from Table A instead of a fname and lname with table joins for normalization?
    Summary: The user has to select his/her employee name from Table A by a drop down on a web page to be added with new information by a submit button to Table B and this information with the employee name is displayed in a new web page.

    • I have a first name (fname) and last name (lname) from table_A displayed from a drop down list on a PHP page. I want the user to select a name (fname and lname together), check other radio buttons, and submit. The submited information will populate table_B, including fname and lname. Each table is in its own database and has a different amount of field names. I have been able to populate table_B with fname OR lname from table_A but not both. I am using an ODBC connection with MS SQL database.
      My query to populate table_B:
      <php>
      <?php
      $query="INSERT INTO table_B (fname, lname, other_fields) VALUES ('$fname', '$lname', '$other_fields');
      ?>
      </php>
      My script to select the first and last names. This code only inputs the fname into table_B. I want it to input fname AND lname.
      <php>
      <?php
      $sql="SELECT lname, fname, group FROM table_A WHERE group='01' ORDER BY fname, lname";
      echo "<select name = fname>";
      $rs=odbc_exec($conn2, $sql);
      while ($row = odbc_fetch_row ($rs))
      {
      echo "<option value=".odbc_result($rs, "fname").">".odbc_result($rs, 'fname' )." ".odbc_result($rs, 'lname' )."</option>";
      }
      echo "</select>";?>
      ?>
      </php>
      I want to <select name = fname> two values but only know how to select one value. Code not important to the question is left out. Thank you in advance for your help.

      • DOES ANYONE HAVE A SOLUTION FOR THIS PROBLEM? Or do you have an example using MS SQL with an ODBC connection with PHP?

        • This question is still unresolved after many tries. The last answer provides no solution. I agree, it is a result unexpected.

          • big.nerd: I appreciate you testing the code.
            The above code displays these results:

            Found the page number!, Page number is 0, so we need to omit -5 results!
            There are 17 ideas.
            Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '-'., SQL state 37000 in SQLExecDirect in E:\Inetpub..........................Untitled-1.php on line 69
            Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in E:\Inetpub..........................Untitled-1.php on line 70
            PREV 1 2 3 4 NEXT
            Warning: odbc_free_result(): supplied argument is not a valid ODBC result resource in E:\Inetpub..........................Untitled-1.php on line 104

            When I remove the error reporting on line 2 I see this error:
            Notice: Undefined index: page in E:\Inetpub..........................Untitled-1.php on line 36
            Found the page number!, Page number is 0, so we need to omit -5 results!
            There are 17 ideas.
            Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '-'., SQL state 37000 in SQLExecDirect in E:\Inetpub..........................Untitled-1.php on line 69
            Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in E:\Inetpub..........................Untitled-1.php on line 70
            PREV 1 2 3 4 NEXT
            Warning: odbc_free_result(): supplied argument is not a valid ODBC result resource in E:\Inetpub..........................Untitled-1.php on line 104

            I don't think it is seeing $page

            Wow, if you tested it successfully, and it doesn't work for me, what's going on?
            To create my database I wrote this script:
            CREATE DATABASE product;
            CREATE TABLE plastic (
            plastic_ID MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
            ename VARCHAR(40) NOT NULL,
            iname VARCHAR(40) NOT NULL,
            PRIMARY KEY (plastic_ID)
            );

            I took out several other columns to keep it simple for testing

            I appreciate your help, thank you.

            • You are correct when you say that I don't understand this. That is why I am asking for help. I want to display 5 records per page. I still get the same result - all pages display the same thing no matter what page I click. I want to increment 5 records at a time per page. Thank you for your help.

              <?php
              $db = odbc_connect('','','');  //put your connection here 
              function inv_rows($r1)  { 
              ob_start(); 
              (int)$number=odbc_result_all($r1); 
              ob_clean(); 
              return $number; 
              } 
              $page = isset($_GET["page"]) ? $_GET["page"] : 1;
              if(empty($page)){$page = 1; }                
              $query = "SELECT * FROM plastic"; // name of table is plastic with primary key of plastic_ID and columns ename and iname. ename represents a name and iname represents an idea
              $num_result = odbc_exec($db, $query); $numrows = inv_rows($num_result);
              echo '<p>There are '.$numrows.' ideas.</p>'; //This works ok $limit = 5; $limitvalue = $page * $limit - ($limit); $limitnew = $limitvalue + $limit; //the SELECT statement below produce a PREV and NEXT action that appears to work BUT the results are the same when clicking to a PREV or NEXT page //I want to show 5 records at a time $sql = "SELECT TOP $limit * FROM plastic WHERE plastic_ID NOT IN (SELECT TOP 10 plastic_ID FROM plastic ORDER BY plastic_ID ASC) ORDER BY plastic_ID ASC"; $result = odbc_exec($db, $sql); while(odbc_fetch_row($result)){
              ?> <table style="width: 600;">
              <tr> <td style="width: 300; height: 25px;">Name:</td> <td style="width: 300; height: 25px;">Idea Name:</td> </tr>
              <tr> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td> </tr> <tr> <td colspan="5" style="height: 25px"><hr/></td> </tr> </table> <?php //PREVIOUS AND NEXT BUTTONS } if($page !=1){ $pageprev = $page - 1; echo "&nbsp;<strong><a href='?page=$pageprev'>PREV</a></strong>&nbsp;"; } else{ echo "&nbsp;PREV&nbsp;"; } $numofpages = $numrows / $limit; for($i = 1; $i <= $numofpages; ++$i){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; } } if(($numrows % $limit) != 0){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; } } if(($numrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; } else{ echo "&nbsp;NEXT&nbsp;"; } odbc_free_result($result);
              exit; ?>
              • I have not been able to write a correct SELECT statement for the page information to change.
                I found a similar problem: http://www.phpbuilder.com/board/showthread.php?t=10352935 for reference.
                The name of my table is plastic. My primary key is plastic_ID. ename represents names and iname represents ideas. I want to show 5 names and ideas per page with pagination. Below are three different SELECT statements that produce the same results if you click on PREV or NEXT buttons. These buttons change when clicked, but the results stay the same.
                I use an ODBC connection with MSSQL and PHP.
                Can you help me write a correct SELECT statement? Returning the complete code helps me understand your edits. I thank you in advance for your help.

                <?php
                $db = odbc_connect('','','');  //put your connection here 
                function inv_rows($r1)  { 
                ob_start(); 
                (int)$number=odbc_result_all($r1); 
                ob_clean(); 
                return $number; 
                } 
                $page = isset($_GET["page"]) ? $_GET["page"] : 1;
                if(empty($page)){$page = 1; }                
                $query = "SELECT * FROM plastic"; // name of table is plastic with primary key of plastic_ID and columns ename and iname.
                $num_result = odbc_exec($db, $query); $numrows = inv_rows($num_result);
                echo '<p>There are '.$numrows.' ideas.</p>'; $limit = 5; $limitvalue = $page * $limit - ($limit); $limitnew = $limitvalue + $limit; //all three SELECT statements below produce a PREV and NEXT action that appears to work BUT the results are the same when clicking to a PREV or NEXT page $sql = "SELECT * FROM (SELECT TOP 5 * FROM (SELECT TOP 5 * FROM plastic ORDER BY ename, iname DESC) as table1 ORDER BY ename, iname DESC) as table2 ORDER BY ename, iname ASC"; //$sql = "SELECT * FROM (SELECT TOP 5 * FROM (SELECT TOP $numrows * FROM plastic ORDER BY ename, iname ASC) as table1 ORDER BY ename, iname DESC) as table2 ORDER BY ename, iname ASC"; //$sql = "SELECT * FROM (SELECT TOP 5 * FROM plastic ORDER BY ename, iname ASC) AS t1 ORDER BY ename, iname DESC"; $result = odbc_exec($db, $sql); while(odbc_fetch_row($result)){
                ?> <table style="width: 600;">
                <tr> <td style="width: 300; height: 25px;">Name:</td> <td style="width: 300; height: 25px;">Idea Name:</td> </tr>
                <tr> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td> </tr> <tr> <td colspan="5" style="height: 25px"><hr/></td> </tr> </table> <?php //PREVIOUS AND NEXT BUTTONS } if($page !=1){ $pageprev = $page - 1; echo "&nbsp;<strong><a href='?page=$pageprev'>PREV</a></strong>&nbsp;"; } else{ echo "&nbsp;PREV&nbsp;"; } $numofpages = $numrows / $limit; for($i = 1; $i <= $numofpages; ++$i){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; } } if(($numrows % $limit) != 0){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; } } if(($numrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; } else{ echo "&nbsp;NEXT&nbsp;"; } odbc_free_result($result);
                exit; ?>
                • big.nerd or anyone else that can help:
                  Thank you for your response. I have three questions, not necessarily in the correct order.
                  1. On line 9 below I am not sure I am calling the field name of "page" the right thing.
                  2. On line 20 below I receive the error "Notice: Undefined index: page." - with the code that is below. I need to know how to fix this error.
                  3. On line 25 I need to rename the value of "yes" to where it displays all the results of the column ename.
                  Details: My table name is "plastic" with primary key of "plastic_ID" and columns of "ename" and "iname". I want my page to display the number of names in the database as a number. Example: There are "XX" names. This part of the code below works. Then I want to display 5 names per page with a PREV and NEXT button to move the user through the results. My connection is ODBC (not my choice) with MSSQL(not my choice) and PHP.
                  Thank you for your help. Returning the complete updated code helps me understand your changes.

                  <?php
                  $db = odbc_connect('','','');  //put your connection here
                  function inv_rows($r1)  {
                  ob_start();
                  (int)$number=odbc_result_all($r1);
                  ob_clean();
                  return $number;
                  }
                  $page = isset($_POST["page"]) ? $_POST["page"] : 1;//question about this line 9
                  if(empty($page)){$page = 1; }                
                  $query = "SELECT * FROM plastic"; //name of table is plastic with columns plastic_ID, ename, and iname.
                  $num_result = odbc_exec($db, $query); $numrows = inv_rows($num_result);
                  echo '<p>There are '.$numrows.' ideas.</p>'; $limit = 5; $limitvalue = $page * $limit - ($limit); $limitnew = $limitvalue + $limit; $max = 5; if (!isset($_GET['page']) || empty($_GET['page'])) { $start = (int)$_GET['page']; //question about this line 20 - Notice: Undefined index: page $start = ($start * $max); } else { $start = 0; } $sql = "SELECT TOP $max * FROM plastic WHERE ename = 'yes' AND (plastic_ID NOT IN (SELECT TOP $start plastic_ID FROM plastic ORDER BY plastic_ID)) ";//question about this line 25 $result = odbc_exec($db, $sql); while(odbc_fetch_row($result)){
                  ?> <table style="width: 600;">
                  <tr> <td style="width: 300; height: 25px;">Name:</td> <td style="width: 300; height: 25px;">Idea Name:</td> </tr>
                  <tr> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td> </tr> <tr> <td colspan="5" style="height: 25px"><hr/></td> </tr> </table> <?php //PREVIOUS AND NEXT BUTTONS } if($page !=1){ $pageprev = $page - 1; echo '&nbsp;<strong><a href="?page='.$pageprev.'">PREV</a></strong>&nbsp;'; } else{ echo "&nbsp;PREV&nbsp;"; } $numofpages = $numrows / $limit; for($i = 1; $i <= $numofpages; ++$i){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; } } if(($numrows % $limit) != 0){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; } } if(($numrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; } else{ echo "&nbsp;NEXT&nbsp;"; } odbc_free_result($result);
                  exit; ?>
                  • It is not clear on my part when I get partial code back from you to put it in the correct place. It might be helpful if the entire code with updates was returned. I am having trouble putting it all together when it is returned.
                    The code below has error: Undefined index: submit on line 21.
                    Thank you in advance for your help.

                    <?php 
                    $db = odbc_connect('','','');  //put your connection here 
                    function inv_rows($r1)  { 
                    ob_start(); 
                    (int)$number=odbc_result_all($r1); 
                    ob_clean(); 
                    return $number; 
                    } 
                    $page = isset($_POST["page"]) ? $_POST["page"] : 1;
                    if(empty($page)){$page = 1; }              
                    $query = "SELECT * FROM plastic"; //name of table is plastic with columns plastic_ID, ename, and iname.
                    $num_result = odbc_exec($db, $query); $numrows = inv_rows($num_result);
                    echo '<p>There are '.$numrows.' ideas.</p>'; $limit = 5; $limitvalue = $page * $limit - ($limit); $limitnew = $limitvalue + $limit; $max = 5; // Number Results/Page $start = 6; // This would be the where you start $perpage = 5; if ($_POST['submit']) {
                    $page = $_POST['page']; $top = ($page - 1) * $perpage; $sql = "SELECT TOP $perpage * FROM plastic WHERE plastic_ID NOT IN (SELECT TOP $top plastic_ID FROM plastic ORDER BY plastic_ID) ORDER BY plastic_ID";
                    } $result = odbc_exec($db, $sql); while(odbc_fetch_row($result)){
                    ?> <table style="width: 600;">
                    <tr> <td style="width: 300; height: 25px;">Name:</td> <td style="width: 300; height: 25px;">Idea Name:</td> </tr>
                    <tr> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td> </tr> <tr> <td colspan="5" style="height: 25px"><hr/></td> </tr> </table> <?php //PREVIOUS AND NEXT BUTTONS } if($page !=1){ $pageprev = $page - 1; echo '&nbsp;<strong><a href="?page='.$pageprev.'">PREV</a></strong>&nbsp;'; } else{ echo "&nbsp;PREV&nbsp;"; } $numofpages = $numrows / $limit; for($i = 1; $i <= $numofpages; ++$i){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; } } if(($numrows % $limit) != 0){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; } } if(($numrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; } else{ echo "&nbsp;NEXT&nbsp;"; } odbc_free_result($result);
                    exit; ?>
                    • Big.nerd: I am not sure what you are saying on that last post. I can hard code a name from the database in the WHERE clause and display an entry of that hard coded name. Of course the hard coding name is for testing only. What is the proper syntax to display all the names if I use the WHERE clause? Or, do I use the WHERE clause?
                      Information about my code:
                      Table name = plastic
                      Primary key = plastic_ID
                      column name = ename
                      column name = iname
                      This page should display how many names (as a number) are in the database, list the first 5 names and the iname information along with the PREV and NEXT buttons.
                      My code with your corrections tells how many names are in the database but does not display any names. The PREV and NEXT buttons don't do anything. I am still not sure if line nine has the proper wording of "page". I appreciate your help with this. Thank you.

                      <?php 
                      $db = odbc_connect('WEB_PROD_IDEAS','write','write123');  //put your connection here 
                      function inv_rows($r1)  { 
                      ob_start(); 
                      (int)$number=odbc_result_all($r1); 
                      ob_clean(); 
                      return $number; 
                      } 
                      $page = isset($_POST["page"]) ? $_POST["page"] : 1;  //not sure of "page" text 
                      if(empty($page)){$page = 1; }                
                      $query = "SELECT * FROM plastic"; //name of table is plastic with columns plastic_ID, ename, and iname.
                      $num_result = odbc_exec($db, $query); $numrows = inv_rows($num_result);
                      echo '<p>There are '.$numrows.' ideas.</p>'; $limit = 5; $limitvalue = $page * $limit - ($limit); $limitnew = $limitvalue + $limit; $max = 5; // Number Results/Page $start = 6; // This would be the where you start, i.e. 16, 31 (1 after last result item) $sql = "SELECT TOP $max * FROM plastic WHERE ename = 'yes' AND (plastic_ID NOT IN (SELECT TOP $start plastic_ID FROM plastic ORDER BY plastic_ID)) "; $result = odbc_exec($db, $sql); while(odbc_fetch_row($result)){
                      ?> <table style="width: 600;">
                      <tr> <td style="width: 300; height: 25px;">Name:</td> <td style="width: 300; height: 25px;">Idea Name:</td> </tr>
                      <tr> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td> </tr> <tr> <td colspan="5" style="height: 25px"><hr/></td> </tr> </table> <?php //PREVIOUS AND NEXT BUTTONS } if($page !=1){ $pageprev = $page - 1; echo '&nbsp;<strong><a href="?page='.$pageprev.'">PREV</a></strong>&nbsp;'; } else{ echo "&nbsp;PREV&nbsp;"; } $numofpages = $numrows / $limit; for($i = 1; $i <= $numofpages; ++$i){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; } } if(($numrows &#37; $limit) != 0){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; } } if(($numrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; } else{ echo "&nbsp;NEXT&nbsp;"; } odbc_free_result($result);
                      exit; ?>
                      • You are correct in saying there are many solutions for paginations with MySQL. However, I am using an ODBC connection (not my choice) with MSSQL (not my choice) written in PHP. I have not found a workable solution with an ODBC connection to a MSSQL database written in PHP. If you have an example you could share, I would appreciate it. Thank you for your help.

                        • Excuse me for not formating my question correctly. Hopefully it is formated correctly now. My question is still unanswered form the previous post.
                          I took your code and replaced it with my code. The result is seeing all entries (not 5 at a time as desired) and the pagination links do not link to the NEXT or PREV pages.
                          I appreciate your response and help.
                          Here is my code.

                          <?php 
                          $db = odbc_connect('',''',''');  //put your connection here 
                          function inv_rows($r1)  { 
                          ob_start(); 
                          (int)$number=odbc_result_all($r1); 
                          ob_clean(); 
                          return $number; 
                          } 
                          $page = isset($_POST["page"]) ? $_POST["page"] : 1;
                          if(empty($page)){$page = 1; } 
                          $query = "SELECT * FROM plastic"; // name of table is plastic with columns plastic_ID, ename, and iname.    	    
                          $num_result = odbc_exec($db, $query); $numrows = inv_rows($num_result);
                          echo '<p>There are '.$numrows.' ideas.</p>'; $limit = 5; $limitvalue = $page * $limit - ($limit); $limitnew = $limitvalue + $limit; if (isset($_POST['submit'])) { switch ($_POST['direction']) { case 'next': $query = "SELECT TOP 5 * FROM plastic WHERE plastic_ID > " . $_SESSION['lastid'] . " ORDER BY plastic_ID"; break; case 'prev': $query = "SELECT * FROM (SELECT TOP 5 * FROM plastic WHERE plastic_ID < " . $_SESSION['firstid'] . " ORDER BY plastic_ID DESC) AS t ORDER BY plastic_ID ASC"; break; default: $query = "SELECT TOP 5 * FROM plastic ORDER BY plastic_ID"; }
                          } $result = odbc_exec($db, $query); while(odbc_fetch_row($result)){
                          ?> <table style="width: 600;">
                          <tr> <td style="width: 300; height: 25px;">Name:</td> <td style="width: 300; height: 25px;">Idea Name:</td> </tr>
                          <tr> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td> </tr> <tr> <td colspan="5" style="height: 25px"><hr/></td> </tr> </table> <?php //PREVIOUS AND NEXT BUTTONS } if($page !=1){ $pageprev = $page - 1; echo "&nbsp;<strong><a href='?page=$pageprev'>PREV</a></strong>&nbsp;"; } else{ echo "&nbsp;PREV&nbsp;"; } $numofpages = $numrows / $limit; for($i = 1; $i <= $numofpages; ++$i){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; } } if(($numrows % $limit) != 0){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; } } if(($numrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; } else{ echo "&nbsp;NEXT&nbsp;"; } odbc_free_result($result);
                          exit; ?>
                          • Thank you for your reply. I took your code and replaced it with my code. The result is seeing all entries (not 5 at a time as desired) and the pagination links do not link to the NEXT or PREV pages.
                            I appreciate your response and help.
                            Here is my updated code.

                            <?php
                            $db = odbc_connect('','',''); //put your connection here
                            function inv_rows($r1) {
                            ob_start();
                            (int)$number=odbc_result_all($r1);
                            ob_clean();
                            return $number;
                            }
                            $page = isset($POST["page"]) ? $POST["page"] : 1;
                            if(empty($page)){$page = 1; }
                            $query = "SELECT FROM plastic"; // name of table is plastic with columns plastic_ID, ename, and iname.

                            $num_result = odbc_exec($db, $query);
                            $numrows = inv_rows($num_result);

                            echo '<p>There are '.$numrows.' ideas.</p>';
                            $limit = 5;
                            $limitvalue = $page
                            $limit - ($limit);
                            $limitnew = $limitvalue + $limit;

                            if (isset($POST['submit'])) {
                            switch ($
                            POST['direction']) {
                            case 'next':
                            $query = "SELECT TOP 5 FROM plastic WHERE plastic_ID > " . $SESSION['lastid'] . " ORDER BY plastic_ID";
                            break;
                            case 'prev':
                            $query = "SELECT
                            FROM (SELECT TOP 5 FROM plastic WHERE plastic_ID < " . $SESSION['firstid'] . " ORDER BY plastic_ID DESC) AS t ORDER BY plastic_ID ASC";
                            break;
                            default:
                            $query = "SELECT TOP 5
                            FROM plastic ORDER BY plastic_ID";
                            }

                            }

                            $result = odbc_exec($db, $query);
                            while(odbc_fetch_row($result)){

                            ?>
                            <table style="width: 600;">

                            <tr>
                            <td style="width: 300; height: 25px;">Name:</td>
                            <td style="width: 300; height: 25px;">Idea Name:</td>
                            </tr>

                            <tr>
                            <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td>
                            <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td>
                            </tr>
                            <tr>
                            <td colspan="5" style="height: 25px"><hr/></td>
                            </tr>
                            </table>
                            <?php //PREVIOUS AND NEXT BUTTONS
                            }
                            if($page !=1){
                            $pageprev = $page - 1;
                            echo "&nbsp;<strong><a href='?page=$pageprev'>PREV</a></strong>&nbsp;"; }
                            else{ echo "&nbsp;PREV&nbsp;"; }
                            $numofpages = $numrows / $limit;
                            for($i = 1; $i <= $numofpages; ++$i){
                            if($i == $page){ echo "&nbsp;[$i]&nbsp;"; }
                            else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; }
                            }
                            if(($numrows % $limit) != 0){
                            if($i == $page){ echo "&nbsp;[$i]&nbsp;"; }
                            else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; }
                            }
                            if(($numrows - ($limit * $page)) > 0){
                            $pagenext = $page + 1;
                            echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; }
                            else{ echo "&nbsp;NEXT&nbsp;"; }
                            odbc_free_result($result);

                            exit;
                            ?>

                            • My auto increment primary key is plastic_ID and the table name is plastic with two column names of ename and iname. I am not sure of the proper syntax and placement of the session vars of $lastid and $firstid in my code.

                              You gave me 2 SELECT statements. Can I ******* that your first SELECT statement replaces my $query statement and your second SELECT statement replaces my $sql statement? If not, I want to understand where to put your two SELECT statements. With plastic_ID as the primary key then the two statements you gave me would be:
                              $query = "SELECT TOP 5
                              FROM plastic WHERE plastic_ID > $lastid ORDER BY plastic_ID";
                              $sql = "SELECT FROM (SELECT TOP 5 FROM plastic WHERE plastic_ID < $firstid ORDER BY plastic_ID DESC) AS t ORDER BY plastic_ID ASC";
                              Would this be correct?
                              I have $page = isset($GET["page"]) ? $GET["page"] : 1; on line 9 and am not sure that "page" is correct.

                              I appreciate your reply. Thank you.

                              • The below script counts the number of entries in the database as a total and then displays 5 entries per page with Previous and Next buttons for pagination. The problem with this code is that the same 5 entries appear on every page. I am not sure about my SELECT statement on line 18 and the specifics on line 9 with GET. Your help would be greatly appreciated. Thank you in advance.

                                <?php
                                $db = odbc_connect('','','');  //put your connection here
                                function inv_rows($r1)  {
                                	ob_start(); 
                                	(int)$number=odbc_result_all($r1);
                                	ob_clean(); 
                                	return $number;
                                	}
                                	$page = isset($_GET["page"]) ? $_GET["page"] : 1;  //not sure of "page" text
                                	if(empty($page)){$page = 1; }			   
                                $query = "SELECT * FROM plastic"; // name of table is plastic with columns ename and iname.
                                $num_result = odbc_exec($db, $query); $numrows = inv_rows($num_result); echo '<p>There are '.$numrows.' ideas.</p>'; $limit = 5; $limitvalue = $page * $limit - ($limit); $limitnew = $limitvalue + $limit; $sql = "SELECT * from (SELECT TOP 5 * from (SELECT TOP 5 * from plastic ORDER BY ename, iname DESC) as table1 ORDER BY ename, iname DESC) as table2 order by ename, iname ASC";
                                $result = odbc_exec($db, $sql); while(odbc_fetch_row($result)){ ?> <table style="width: 600;"> <tr> <td style="width: 300; height: 25px;">Name:</td> td style="width: 300; height: 25px;">Idea Name:</td> </tr> <tr> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "ename"); ?></td> <td style="width: 300; height: 25px;"><?php echo odbc_result($result, "iname"); ?></td> </tr> <tr> <td colspan="5" style="height: 25px"><hr/></td> </tr> </table> <?php //PREVIOUS AND NEXT BUTTONS } if($page !=1){ $pageprev = $page - 1; echo "&nbsp;<strong><a href='?page=$pageprev'>PREV</a></strong>&nbsp;"; } else{ echo "&nbsp;PREV&nbsp;"; } $numofpages = $numrows / $limit; for($i = 1; $i <= $numofpages; ++$i){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</a></strong>&nbsp;"; } } if(($numrows % $limit) != 0){ if($i == $page){ echo "&nbsp;[$i]&nbsp;"; } else{ echo "&nbsp;<strong><a href='?page=$i'>$i</strong></b>&nbsp;"; } } if(($numrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo "&nbsp;<strong><a href='?page=$pagenext'>NEXT</a></strong>&nbsp;"; } else{ echo "&nbsp;NEXT&nbsp;"; } odbc_free_result($result); exit; ?>