Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post

    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

  • #2
    New to the CF scene
    Join Date
    Aug 2008
    Location
    Liverpool, UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    735
    Thanks
    4
    Thanked 1 Time in 1 Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •