home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / dbbrow.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  2.3 KB  |  88 lines

  1. DB-Browser 
  2.  
  3. This little handy code display the prev- and next-Button for Database-browsing. It shows the page where your are right now. 
  4.  
  5. <?
  6. /*
  7.  Filename : demoBrowsDB.php3
  8.   This Script can be used to browse a Database.
  9.   the scipt contains prev- , Pages- and next- Button
  10.   the only thing you have to do is :
  11.  
  12.      GetMaxRowsToShow = YOUR Select-statement
  13.      needed to calculate the total number of Rows
  14.      for example
  15.                 $GetMaxRowsToShow = "select count(*) as Anzahl from YOURTABLE where col1 = whatever"
  16.  
  17.      $GetRows = YOUR Select-statement
  18.      The Rows you want to show
  19.      for example
  20.             GetRows = "select col1,col2 col3  from YOURTABLE where col1 = whatever limit $RL,$MaxRow "
  21.  
  22.       $RL  = Starting with Row
  23.  
  24.       $MaxRow = number of Rows to display
  25.  
  26. TIP : place the Script on your Webserver and let it run!
  27.       Take care of the Parameter when you put it in your PHP-File!
  28.  
  29.  see it in action at http://www.it-development.de
  30.  if you have an questions : Bernhard Bauder
  31.                             bbauder@it-development.de
  32.  Have fun.
  33.  Berni
  34.  28.03.2000
  35. */
  36.  
  37. $MaxRow = 10;
  38.  
  39. // is this the first time the Script is called?
  40.      if (!isset($CR))
  41.      {
  42.             // $result = mysql_query($GetMaxRowsToShow ) or die ("Database error");
  43.             // $row=mysql_fetch_array($result);
  44.              //  $CR= $row["Anzahl"];
  45.              $CR=31;   // delete this for your use
  46.  
  47.              $RL=0;
  48.      }
  49.  
  50.  
  51.  
  52.  
  53.      // get the Number of pages
  54.      $AnzahlSeiten=intval($CR/$MaxRow);
  55.      if ($AnzahlSeiten < ($CR/$MaxRow)){ $AnzahlSeiten++;}
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.      echo "<CENTER>";
  63.      // prev Button
  64.       if   ($RL > 0) {
  65.        $y=$RL-$MaxRow;
  66. // take care of your Parameter
  67.        echo "[<a href=\"demoBrowsDB.php3?CR=$CR&RL=$y\"><<</a>] ";
  68.       }
  69.      // Pages
  70.      for ($i = 1; $i <= $AnzahlSeiten; $i++)
  71.      {   $y=($i*$MaxRow)-$MaxRow;
  72.       if ($y==$RL){echo "<B>";}
  73. // take care of your Parameter
  74.          echo "[<a href=\"demoBrowsDB.php3?CR=$CR&RL=$y\">$i</a>] ";
  75.        if ($y==$RL){echo "</B>";}
  76.      }
  77. //  next button
  78.      if   ($RL < ($CR-$MaxRow)) {
  79.        $y=$RL+$MaxRow;
  80. // take care of your Parameter
  81.        echo "[<a href=\"demoBrowsDB.php3?CR=$CR&RL=$y\">>></a>] ";
  82.        }
  83.      echo "</CENTER>";
  84. // now make a select with -> limit $RL,$MaxRow
  85.  
  86. ?>
  87.  
  88.