i've been working with files from other people to use as reference and i have to admit that it's so hard to understand pagination.

i wish that there is a book out there that I can just buy and read about it.

I would post my codes here, but it's soo sloppy. trying to think about the logic...

i just want a simple pagination like our forums or atleast like googles.

    Post the code... or just tell us how far are you in terms of the algorithm. Or at least give us were you're stuck.

      Goto the Code Critique Forum. I have posted a Pagination Script there. it may help you out

        You know Hoangsta, I know a lot coding techniques, I could say I mastered them successfully but I just can't get pagination down. I was there was something that explain each line of code because I just don't get the process...

          guys, here is the code that I used to do my pagination

          
          <FORM method="get" action="searching.php">
          <INPUT size=40 name=searchterm type=text>
          <INPUT type="submit" name="submit" value="search">
          
          

          searching.php code:

          <?php 
          
          $searchterm = $_GET["searchterm"];			
          trim($searchterm);
          if (!$searchterm)
          {
          echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;You have not entered a search.<br><br>";
          
          exit;
          }
          $searchterm = addslashes($searchterm);
          // Database Connection 
          include 'db.php';
          if (!$db)
          {
          echo "Error: Could not connect to database. Please try again later.";
          exit;
          }
          
          // If current page number, use it 
          // if not, set one! 
          
          if(!isset($_GET['page'])){ 
              $page = 1; 
          } else { 
              $page = $_GET['page']; 
          } 
          
          // Define the number of results per page 
          $max_results = 5; 
          
          // Figure out the limit for the query based 
          // on the current page number. 
          $from = (($page * $max_results) - $max_results); 
          
          // Perform MySQL query on only the current page number's results 
          
          $sql = mysql_query("SELECT * FROM BusinessName 
          					WHERE business_name LIKE '%$searchterm%' 
          					ORDER BY business_name
          					LIMIT $from, $max_results"); 
          
          
          $num_results = mysql_num_rows($sql);
          echo "Your search for <b>\"" .$searchterm. "\"</b> returns <b>\"".$num_results."\"</b> records</p>"; 
          for ($i=0; $i <$num_results; $i++) {
          $row = mysql_fetch_array($sql);
          
          // Build your formatted results here. 
          echo "<p><strong>".($i+1).".  ";	
          echo "<a href=\"http://www.help.com\">";
          echo htmlspecialchars( stripslashes($row["business_name"]));
          echo "</a></strong><br> ";
          echo "<a href=\"http://www.maporama.com\" target=\"_blank\">Map it!</a>";
          echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <a href=\"http://{$row['webpagelink']}\" target=\"_blank\">";
          echo htmlspecialchars (stripslashes($row["webpagelink"]));
          echo "</a><br />";
          echo htmlspecialchars (stripslashes($row["business_address"]));
          echo ", ";
          echo htmlspecialchars (stripslashes($row["bus_city"]));
          echo ", ";
          echo htmlspecialchars (stripslashes($row["businessacct_state_country"]));
          echo " ";
          echo htmlspecialchars (stripslashes($row["bus_zip"]));
          echo "<br>Phone:<strong>  ";
          echo htmlspecialchars (stripslashes($row["business_phone"]));
          echo "</strong>&nbsp;&nbsp;Fax:  ";
          echo htmlspecialchars (stripslashes($row["business_fax"]));
          echo "</p>";
          }
          
          // Figure out the total number of results in DB: 
          $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM BusinessName"),0); 
          
          // Figure out the total number of pages. Always round up using ceil() 
          $total_pages = ceil($total_results / $max_results); 
          
          // Build Page Number Hyperlinks 
          echo "<center>Select a Page&nbsp;"; 
          
          // Build Previous Link 
          if($page > 1){ 
              $prev = ($page - 1); 
              echo "<a href=\"".$_SERVER['searching.php']."?page=$prev\"><< Previous</a>&nbsp;"; 
          } 
          
          for($i = 1; $i <= $total_pages; $i++){ 
              if(($page) == $i){ 
                  echo "$i&nbsp;"; 
                  } else { 
                      echo "<a href=\"".$_SERVER['searching.php']."?page=$i\">$i</a>&nbsp;"; 
              } 
          } 
          
          // Build Next Link 
          if($page < $total_pages){ 
              $next = ($page + 1); 
              echo "<a href=\"".$_SERVER['searching.php']."?page=$next\">Next >></a>"; 
          } 
          echo "</center>"; 
          
          ?> 
          

          when i hit the "next" or "2" it just shows me a page that tells me that You have not entered a search, which I did up there. The reason for this echoing is to tell the user that search was empty.

          I'm trying to develope a search engine to search for specific words, not just what is in the database.

          Further, I took out

          trim($searchterm);
          if (!$searchterm)
          {
          echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;You have not entered a search.<br><br>";
          
          exit;
          }
          

          and it allows me to see my "Previous, Next" etc. In the record prior to the "Previous, Next", it shows 5 results.
          1,2,3,4,5 when I hit Next or "2", it starts at 1 again.

            for($i = 1; $i <= $total_pages; $i++){ 
                if(($page) == $i){ 
                    echo "$i&nbsp;"; 
                    } else { 
                        echo "<a href=\"".$_SERVER['searching.php']."?page=($i*$max_results)\">$i</a>&nbsp;"; 
                } 
            }  

            Try that for your "FOR" loop

              how is ur pagination doing? my pagination is weird. it doesn't keep the # of counts when it goes to the second page

                I gave up on it for now. Have other things to learn!

                  hey, go to this site, it has an EZ to learn pagination. I modified it to fit my needs, but if you just want to be able to navigate between pages, this is the script. I've tested out and it works.

                  http://www.devshed.com/Server_Side/PHP/Paginating/page1.html

                  Good luck. I spent hella hours on pagination from forums to forums and discovered that site out from doing research.

                  if you modify yours to do something else besides what is already given, let me know. I'm wokring on....

                  echoing out the searchterm which will give me the total amout of outputs in integer.

                  then if i limit my page to 5, but have a total of 8 records, then it will show

                  Results 1 to 5 shown. on the first page.
                  Results 6 to 8 shown. on the second page.

                  anyways, good luck.

                    Write a Reply...