Jump to content

PHP/MySQL w/ADODB Paging & Search


quasiman

Recommended Posts

I'm trying to use ADODB with a paging class (class.GenericEasyPagination.php) and search form.

They both work (paging and search), but when I try to page through the search results, the session doesn't stay.  I think I'm missing something simple, but can't see what!

 

PHP 5.3.1

MySql 5.1.41

Here's my code...

<?php
$host = 'localhost';
$user = 'root';
$database = 'phpdbstuff';
$password = '';
// include the ADODB library
include("adodb5/adodb.inc.php");
include_once("adodb5/session/adodb-session2.php");
include("EasyPager-KB/_common_includes/class.GenericEasyPagination.php");
ADOdb_Session::config($driver, $host, $user, $password, $database,$options=false);
session_start();
///////////////////////////////////////////////////////////////////
// Define Constants
if ($_GET["page"]!=""):        $page    = $_GET["page"];    else:    $page    = 1;        endif;
define ('RECORDS_BY_PAGE',5);
define ('CURRENT_PAGE',$page);
///////////////////////////////////////////////////////////////////
// Connection Of DataBase
$objConnection = &ADONewConnection('mysql'); 
$objConnection->Connect($host,$user,'',$database);
///////////////////////////////////////////////////////////////////
// Select Records By "PageExecute Method"
$strSQL = "SELECT id,username,firstname,lastname FROM players";
$_SESSION['q'] = $_POST['q'];
$srch = $_SESSION['q'];
if (isset($srch)) {
$strSQL .= " WHERE firstname LIKE \"%$srch%\" ";
echo "searched for " . $srch . "<br />";
}
$objConnection->SetFetchMode(ADODB_FETCH_ASSOC);
$rs = $objConnection->PageExecute($strSQL,RECORDS_BY_PAGE,CURRENT_PAGE);
///////////////////////////////////////////////////////////////////
// Search Form
?>
<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  <input type="text" name="q" />
  <input type="submit" name="Submit" value="Search" />
</form>
<?php
///////////////////////////////////////////////////////////////////
// Display Records
if (!$rs->EOF)
{
    $recordsFound = $rs->_maxRecordCount;
    echo "RecordsLits:<br><br>";
    while(!$rs->EOF)
    {
        echo "<strong>User Name:</strong> ".$rs->fields["username"]." (<strong>id</strong>: ".$rs->fields["id"].")<br>";
        @$rs->moveNext();
    }
    ///////////////////////////////////////////////////////////////////
    // Pagination
    $GenericEasyPagination =& new GenericEasyPagination(CURRENT_PAGE,RECORDS_BY_PAGE);
    $GenericEasyPagination->setTotalRecords($recordsFound);
    echo "<br>";
    echo "<strong>Records found: </strong>".$recordsFound;
    echo "<br>Records ";
    echo $GenericEasyPagination->getListCurrentRecords();
    echo "<br>";
    echo $GenericEasyPagination->getNavigation();
    echo "<br>";
    echo $GenericEasyPagination->getCurrentPages();
    echo "<br>";
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/205593-phpmysql-wadodb-paging-search/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.