Search and Database Browser

From: Date: Fri, 01 Sep 2000 02:30:38 +0000
Subject: Search and Database Browser
Groups: php.db 
Request: Send a blank email to php-db+get-2544@lists.php.net to get a copy of this message
Hi, I have a problem with searching and browsing the results in multiple pages (15 rows each page). s.php3 ->(pass the search text)-> v.php3 eg. search text - "michael", in v.php3 - I get xx total records, in few pages. everything is alright until the next page. I can only browse the first page (15 records) and then when I click on the next 15 rows, I got a blank page. The $stmt is empty the next time around. How do I retain the value of a variable even after a page refresh? s.php3 - Form that send the search text v.php3 - code below <? // // get database name, username, hostname, and password from external file include "db.inc"; $MaxRow = 15; // Has the form been submitted if ($REQUEST_METHOD=='POST') { // is this the first time the Script is called?
     if (!isset($CR))
     {
             // Edit this SELECT variable
$searchstmt = "SELECT * from customer where "; $searchstmt .= "cust_id like '%$search_text%' or "; $searchstmt .= "c_coy like '%$search_text%' or "; $searchstmt .= "c_name like '%$search_text%' or "; $searchstmt .= "c_addr1 like '%$search_text%' or "; $searchstmt .= "c_addr2 like '%$search_text%' or "; $searchstmt .= "c_addr3 like '%$search_text%' or "; $searchstmt .= "c_tel like '%$search_text%' or "; $searchstmt .= "c_fax like '%$search_text%' or "; $stmt = substr($searchstmt, 0, strlen($searchstmt)-3); $sqlstmt = $stmt . " " . "ORDER BY c_coy"; $sql = mysql_query($sqlstmt); if (!$sql) {
    echo "SQL Error! " . mysql_error() . "</P>\n";
} $results = mysql_num_rows($sql);
             $CR= $results;
             $RL=0;
     }
     ?>
     <a href="s.php3">[Back to Index Page] </a><P><?
     echo "Total Records Found: $CR";
// get the Number of pages
     $num_pages=intval($CR/$MaxRow);
     if ($num_pages < ($CR/$MaxRow)){ $num_pages++;}
     echo "<CENTER>";
// prev Button
      if   ($RL > 0) {
       $y=$RL-$MaxRow;
// take care of your Parameter
       echo "[<a href=\"v.php3?CR=$CR&RL=$y\">Prev $MaxRow </a>] ";
      }
// Pages
     for ($i = 1; $i <= $num_pages; $i++)
     {   $y=($i*$MaxRow)-$MaxRow;
      if ($y==$RL){echo "<B>";}
// take care of your Parameter
         echo "[<a href=\"v.php3?CR=$CR&RL=$y\">$i</a>] ";
       if ($y==$RL){echo "</B>";}
     }
// next button
     if   ($RL < ($CR-$MaxRow)) {
       $y=$RL+$MaxRow;
// take care of your Parameter
       echo "[<a href=\"v.php3?CR=$CR&RL=$y\">Next $MaxRow </a>] ";
       }
     echo "</CENTER> <P>";
// now make a select with -> limit $RL,$MaxRow $sqlstmt = $stmt . " " . "ORDER BY c_coy LIMIT $RL,$MaxRow"; $sql = mysql_query($sqlstmt); if (!$sql) {
       echo "SQL Error! " . mysql_error() . "</P>\n";
} $results = mysql_num_rows($sql); ?> // Display the results
    <table border=3><?
    echo "<UL>\n";
    while ($result = mysql_fetch_array($sql)) {
          $row_id          = $result["row_id"];
          $cust_id         = $result['cust_id'];
          $c_coy           = $result['c_coy'];
          $c_name          = $result['c_name'];
          $c_addr1         = $result['c_addr1'];
          $c_addr2         = $result['c_addr2'];
          $c_addr3         = $result['c_addr3'];
          $c_tel           = $result['c_tel'];
          $c_tel_ext       = $result['c_tel_ext'];
          $c_fax           = $result['c_fax'];
?> <TR><TD><? echo $cust_id; ?> <TD><? echo $c_coy; ?> <TD><? echo $c_name; ?> <TD><? echo $c_addr1; ?> <TD><? echo $c_addr2; ?> <TD><? echo $c_addr3; ?> <TD><? echo $c_tel; ?> <TD><? echo $c_tel_ext; ?> <TD><? echo $c_fax; ?> <? } ?></table><? } ?> Is there any ready code that can do the above? It will be good if someone has coded this before. Any help would be great. Thanks in advance.

« previous php.db (#2544) next »