Login   Register  
PHP Classes
elePHPant
Icontem

File: sample3.txt

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Shiegege  >  Paging for MySQL  >  sample3.txt  >  Download  
File: sample3.txt
Role: Example script
Content type: text/plain
Description: Sample Search Mode
Class: Paging for MySQL
Create a query results page navigation bar
Author: By
Last change: add url
Date: 10 years ago
Size: 1,473 bytes
 

Contents

Class file image Download
<?
// see online: http://kentung.f2o.org/scripts/paging/sample3.php
include("./form.html");

require(
"paging_class.php");

$paging=new paging(10,5"<img src=\"images/prev.gif\" alt=\"prev\">""<img src=\"images/next.gif\" alt=\"next\">""(%%number%%)");
$paging->db("localhost","username","password","dbname");

$qw=explode_keyword($_GET[keyword]);

$paging->query("select * from paging where $qw order by MY_FIELD desc");

$page=$paging->print_info();

if (!empty(
$page["keyword"]))
    echo 
"Keyword : <b>$page[keyword]</b><br>\n";

if (empty(
$page["total"])) {
    echo 
"<u>Not Found</u>\n";
} else {
    echo 
"Data $page[start] - $page[end] of $page[total] [Total $page[total_pages] Pages]<br>\n";
}

echo
"    <table border=\"1\" cellspacing=\"0\" width=\"100%\" cellpadding=\"2\">\n";

while (
$result=$paging->result_assoc())
{
    
$color=$paging->print_color("yellow","#FFCCCC")
    
?>
        <tr>
            <td width="3%" bgcolor="<?=$color?>"><?=$paging->print_no()?></td>
            <td width="98%" bgcolor="<?=$color?>"><?=$result[MY_FIELD]?></td>
        </tr>
    <?
}

echo
"    </table>\n";

echo 
$paging->print_link();

//FUNCTION
function explode_keyword($q)
{
        
//trim
        
$q=trim($q);
        
$q=preg_replace("/[\s]+/"," ",$q);

            
$mode="AND";
            
$q2=explode(" ",$q);
            for (
$i=0;$i<count($q2);$i++) {
                
$condition=$condition."MY_FIELD"." like '%".$q2["$i"]."%' ".$mode." ";
            }
            
$condition=substr($condition,0,-4);
            return 
$condition;
}
?>