#1 (permalink)  
Old 07-31-2008, 12:04 PM
Registered User
 
Join Date: Jul 2004
Posts: 249
paging recordsets

Perfect PHP Pagination [PHP & MySQL Tutorials]
I'm trying to use this model and fill in what I need to:
PHP Code:
<?php
require_once "Paginated.php";
require_once 
"DoubleBarLayout.php";
?>
<html>
    <head>
        <title>Pagination</title>
        <style type="text/css">
            body {
                font-family: Verdana;
                font-size: 13px;
            }
            a {
                text-decoration: none;
            }
            a:hover {
                text-decoration: underline;
            }
        </style>
    </head>
    <body>
    <?php
    $con 
mysql_connect("","root","");
    if (!
$con){
        die(
'Could not connect: ' mysql_error());
    }
    
mysql_select_db("kjv"$con);
    
/*
    function bookTitles(){
        $booktitlesarray = array();
        $query = "SELECT * FROM bible WHERE 1=1 AND";
        $query .= " CASE WHEN text_data LIKE '%" .$newSearchTheseArr[$j]. "%' THEN 1 ELSE 0 END";
        $query .= " ORDER BY id";
        //echo $query;
        $result = mysql_query($query);
        if($result){
            while($row = mysql_fetch_assoc($result)){
                $booktitlesarray[] = "<span class='goToBookChapter' style='font-weight: bold;'>".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />".$row['text_data']."<br />";
            }
        }
        return $booktitlesarray;
    } 
    */
    /*******************************************************************************************************/
    //new
    
$searchThese "the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt";
    
$searchTheseArray explode(' '$searchThese);
     
    
# Where the good words go
    
$bigWords = array();
    
    
# Cycle through each word
    
foreach ($searchTheseArray as $word) {
      
# if it's 4 chars or less
      
if (strlen($word) > && !in_array($word,$bigWords)) {
        
# add it to the small words
        
$bigWords[] = $word;
      }
    }
    
    
print_r($bigWords);
    
$query="SELECT * FROM bible WHERE 1=1 AND";

    
//to sort out all words with length less than 4 like AND, OR, BUT...
    
for ($i=0$i count($bigWords); $i++){
        if(
$bigWords[$i]!=""){
            
$query.=" CASE WHEN text_data LIKE '%" .$bigWords[$i]. "%' THEN 1 ELSE 0 END\n";
            if(
$i!=count($bigWords)-1){
                
$query.=" +";
                }else{
                
//removes the OR from the last line and replaces with the following
                //for results of words > 3
                
$query.= " > 3";
                }
            }
        }
    
$query .= " ORDER BY id";
    echo 
"<br /><br />".$query."<br />";
    echo 
"Words searched for:<br />\n";
    
$bigWords array_values($bigWords);
    
    
$COLORS = array('red','Teal','blue','Magenta','green','PaleGreen','orange','purple','Pink','YellowGreen','Sienna','aqua','Gray','LightBlue','MediumTurquoise','DarkRed');
    
//to make $k start the $COLORS from 0
    
$k 0;
    for (
$j=0$j count($bigWords); $j++){
            if(
$bigWords[$j]!=""){
                echo 
"<span style='font-weight: bold; color: ".$COLORS[$k].";'>".$bigWords[$j]."</span>\n";
                if(
$j!=count($bigWords)-1){
                    echo 
" + ";
                    }else{
                    
//removes the OR from the last line and replaces with the following
                    //for results of words > 3
                    
echo ".";
                    }
                
$k++;    
            }
    }
    
$result mysql_query($query);
    
$pagedResults = new Paginated($row10$page);
    
$page $_GET['page'];
    while(
$row $pagedResults->fetchPagedRow(mysql_fetch_assoc($result))){
        echo 
"<br />\n";
        echo 
"<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n";
    
        
$strText $row['text_data'];
        for(
$m=0$m count($bigWords); $m++){
            
$strText preg_replace("/(".$bigWords[$m].")/i""<span class=\"\" id=\"\" style=\"color:".$COLORS[$m]."; font-weight:bold;\">$1</span>"$strText);
            }
        echo 
"<br />\n";
        echo 
$strText."<br />\n";
        }
        
//important to set the strategy to be used before a call to fetchPagedNavigation
        
$pagedResults->setLayout(new DoubleBarLayout());
        echo 
$pagedResults->fetchPagedNavigation();    
    
mysql_close($con);    
    
/*******************************************************************************************************/
    /*
    $names = $strText; 
    //$names = bookTitles(); 
    $page = $_GET['page'];
    
    //constructor takes three parameters
    //1. array to be paged
    //2. number of results per page (optional parameter. Default is 10)
    //3. the current page (optional parameter. Default  is 1)
    $pagedResults = new Paginated($names, 10, $page);
    echo "<div>\n";
    while($row = $pagedResults->fetchPagedRow()){
        echo "<span>{$row}</span><br />\n";
    }
    echo "</div>\n";
    mysql_close($con);
    //important to set the strategy to be used before a call to fetchPagedNavigation
    $pagedResults->setLayout(new DoubleBarLayout());
    echo $pagedResults->fetchPagedNavigation();
    */
    
?>
</body>
</html>
I don't think this is the right way of writing:
PHP Code:
    while($row $pagedResults->fetchPagedRow(mysql_fetch_assoc($result))){ 
Reply With Quote

  #2 (permalink)  
Old 07-31-2008, 08:45 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,445
Please keep in mind that I have not used or tested the code you provided, so I am only going on what I can see from reading the code.

However, it appears that you will need to run the sql query and retrieve the recordset array before instantiating the classes.

The fetchPagedRow function does not accept any parameters, so there is no point in trying to call it with your SQL query.

I think what you need to do is something like:
PHP Code:
if($result mysql_query($query)) {
$tmparr = array();
while(
$rs mysql_fetch_assoc($result)) {
$tmparr[] = $rs;
}
}
$page $_GET['page'];
$pagedResults = new Paginated($tmparr,10,$page);
while(
$row $pagedResults->getPagedRow()) { 
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
  #3 (permalink)  
Old 07-31-2008, 10:31 PM
Registered User
 
Join Date: Jul 2004
Posts: 249
Quote:
Originally Posted by curtiss View Post
Please keep in mind that I have not used or tested the code you provided, so I am only going on what I can see from reading the code.

However, it appears that you will need to run the sql query and retrieve the recordset array before instantiating the classes.

The fetchPagedRow function does not accept any parameters, so there is no point in trying to call it with your SQL query.

I think what you need to do is something like:
PHP Code:
if($result mysql_query($query)) {
$tmparr = array();
while(
$rs mysql_fetch_assoc($result)) {
$tmparr[] = $rs;
}
}
$page $_GET['page'];
$pagedResults = new Paginated($tmparr,10,$page);
while(
$row $pagedResults->getPagedRow()) { 
Oh so there has to be 2 while loops?
In my previous attempt I used two while loops which worked but for other reasons and the difficulty to understand the whole thing I decided to start from scratch:
PHP Code:
   $result mysql_query($query);
   if(
$result){
      while(
$row mysql_fetch_assoc($result)){
          
$booktitlesarray[] = "\t\t\t<span class='goToBookChapter' style='font-weight: bold; color: black;'>".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n\n\t\t\t".$row['text_data'];
      }
   }
   return 
$booktitlesarray;


    
//$names = bookTitles(); 

    
$page $_GET['page'];
    
$queryVars $newSearchTheseArr;
    echo 
"<span style='font-weight: bold; color: black;'>".$queryVars."</span><br />\n";
    
//constructor takes three parameters
    //1. array to be paged
    //2. number of results per page (optional parameter. Default is 10)
    //3. the current page (optional parameter. Default  is 1)
    //$pagedResults = new Paginated($names, 10, $page);
    
$pagedResults = new Paginated(bookTitles($searchTheseArr), 10$page);
    echo 
"<div>\n";
    while(
$row $pagedResults->fetchPagedRow()){
        echo 
"\t\t<span>\n{$row}\n\t\t</span><br />\n";
    }
    echo 
"</div>\n";
    
mysql_close($con);
    
//important to set the strategy to be used before a call to fetchPagedNavigation
    
$pagedResults->setLayout(new DoubleBarLayout());
    echo 
$pagedResults->fetchPagedNavigation(); 
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio

Last edited by gilgalbiblewhee; 07-31-2008 at 10:45 PM.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
paging with for loop gilgalbiblewhee Programming and Scripting 1 07-17-2008 11:25 AM
paging recordsets gilgalbiblewhee Programming and Scripting 18 07-03-2008 05:59 PM
paging with JavaScript and ASP "Next" "Previous" gilgalbiblewhee Programming and Scripting 1 07-05-2007 10:19 AM


All times are GMT -5. The time now is 12:08 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter