how to limint the number of result that occur in one page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sheau Wei
    New Member
    • Sep 2006
    • 34

    how to limint the number of result that occur in one page?

    i have create a search engin for searching a database. Then i want to limit the result that appear in one page. Let say 10 result in one page. How can i do it with php?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Best is to look at the numerous PHP pagination scripts that you can use freely. For example: http://www.tkap.org/paginator/index.php

    Ronald :cool:

    Comment

    • Sheau Wei
      New Member
      • Sep 2006
      • 34

      #3
      According to the webpage u give me last time, i had write acode abut the pagination. But now i have the problem at this line

      "while(list($Na meItem) = mysql_fetch_arr ay($result2)) { "

      If i want to put all the selected field instead of only NameItem as what i had i done in the query, how should i do?

      <?
      //required file for database connection
      require("config .php");
      $query = "SELECT *FROM listofitem ";
      $result = mysql_query($qu ery);

      $num_record = mysql_num_rows( $result);

      $display = 10;

      if (empty($startro w)) {
      $startrow=0;
      }

      $query2 = "SELECT *FROM listofitem LIMIT $startrow, $display";
      $result2 = mysql_query($qu ery2);

      print("<table border=0><tr>") ;

      $counter = 0;

      while(list($Nam eItem) = mysql_fetch_arr ay($result2)) {

      if ($counter == 3) {
      print("</tr><tr>");

      $counter = 0;
      }

      print("<td bgcolor=#004A80 width=200 height=200 align=center><f ont color=#FFFFFF>$ NameItem</font><br><font color=#FFFFFF>" );


      $counter = $counter + 1;
      }

      if ($startrow != 0) {
      $prevrow = $startrow - $display;
      print("<a href=\"$PHP_SEL F?startrow=$pre vrow\">Previous </a> ");
      }

      $pages = intval($num_rec ord / $display);

      if ($num_record % $display) {

      $pages++;
      }

      if ($pages > 1) {
      for ($i=1; $i <= $pages; $i++) { // Begin loop
      $nextrow = $display * ($i - 1);
      print("<a href=\"$PHP_SEL F?startrow=$nex trow\">$i</a> ");
      }
      }

      if (!(($startrow / $display) == $pages) && $pages != 1) {

      $nextrow = $startrow + $display;
      print("<a href=\"$PHP_SEL F?startrow=$nex trow\">Next</a>");
      }

      if ($num_record < 1) {
      print("<table border=0 width=795><tr>< td>$XX</td></tr></table>");
      }
      ?>

      Comment

      Working...