Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-31-2008, 05:11 PM   PM User | #1
gilgalbiblewhee
Regular Coder

 
Join Date: Mar 2005
Posts: 735
Thanks: 4
Thanked 1 Time in 1 Post
gilgalbiblewhee is an unknown quantity at this point
paging recordsets

http://www.sitepoint.com/article/perfect-php-pagination
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))){ 
__________________
Compare bible texts (and other tools):
TheWheelofGod
gilgalbiblewhee is offline   Reply With Quote
Old 08-01-2008, 02:38 AM   PM User | #2
ST-Mike
New to the CF scene

 
Join Date: Aug 2008
Location: Liverpool, UK
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
ST-Mike is an unknown quantity at this point
To be honest I'm tired and haven't looked at it properly, but judging from the commented out areas, shouldn't it read:

PHP Code:
while($row $pagedResults->fetchPagedRow()){ 
following creating the object?
ST-Mike is offline   Reply With Quote
Old 08-01-2008, 03:29 AM   PM User | #3
gilgalbiblewhee
Regular Coder

 
Join Date: Mar 2005
Posts: 735
Thanks: 4
Thanked 1 Time in 1 Post
gilgalbiblewhee is an unknown quantity at this point
Quote:
Originally Posted by ST-Mike View Post
To be honest I'm tired and haven't looked at it properly, but judging from the commented out areas, shouldn't it read:

PHP Code:
while($row $pagedResults->fetchPagedRow()){ 
following creating the object?
By doing that for some reason it's ignoring whatever's in the while loop.
__________________
Compare bible texts (and other tools):
TheWheelofGod
gilgalbiblewhee is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

Forum Jump


All times are GMT +1. The time now is 05:02 AM.


Advertisement
Log in to turn off these ads.