Go Back   HTMLCenter Web Development Forums > Web Design and Development > Programming and Scripting

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 08-06-2008, 02:28 PM
Registered User
 
Join Date: Jul 2004
Posts: 219
paging an array of records

The original script is found on:
Perfect PHP Pagination [PHP & MySQL Tutorials]

PHP Code:
<?php
require_once "Paginated.php";
require_once 
"DoubleBarLayout.php";
?>
<html>
<head>
<title>Pagination</title>

<!-- Just a little style formatting. Has no bearing on example -->
<style type="text/css">
    body {
        font-family: Verdana;
        font-size: 13px;
    }
    
    a {
        text-decoration: none;
    }
    
    a:hover {
        text-decoration: underline;
    }
</style>
<!-- End style formatting -->
</head>

<body>

    <?php
    
//create an array of names in alphabetic order. A database call could have retrieved these items
    
$names = array("Andrew""Bernard""Castello""Dennis""Ernie""Frank""Greg""Henry""Isac""Jax""Kester""Leonard""Matthew""Nigel""Oscar");
    
    
$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($names10$page);
    
    echo 
"<ul>";

    while(
$row $pagedResults->fetchPagedRow()) {    //when $row is false loop terminates
        
echo "<li>{$row}</li>";
    }
    
    echo 
"</ul>";
    
    
//important to set the strategy to be used before a call to fetchPagedNavigation
    
$pagedResults->setLayout(new DoubleBarLayout());
    echo 
$pagedResults->fetchPagedNavigation();
    
?>
</body>
</html>
It consists an array of 15 names.
WHat I needed to do is have a query and set the result into an array and replace the $names above. I replaced it with a function. And within the function called getQuery($bigWords) I placed both the query and the while loop of $results.
See next posting.
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
Reply With Quote

  #2 (permalink)  
Old 08-06-2008, 02:55 PM
Registered User
 
Join Date: Jul 2004
Posts: 219
$bigWords is an array of words > 4 letters. The rest of the words have previously sorted out.
PHP Code:
function getQuery($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";
        
$theresult = array();
        
//$theresult[] = "";
        //$theresult[] = $query;
        
$result mysql_query($query);

    while(
$row mysql_fetch_assoc($result)){
        
$strText $row['text_data'];
        
$COLORS = array('red','Teal','blue','Magenta','green','PaleGreen','orange','purple','Pink','YellowGreen','Sienna','aqua','Gray','LightBlue','MediumTurquoise','DarkRed');
        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);
            }
        
$theresult[] = "<br />\n<span class=\"goToBookChapter\" style=\"font-weight: bold;\">".$row['book_title']." ".$row['chapter'].":".$row['verse']."</span><br />\n".$strText;
        }
        return 
$theresult;
        echo 
"<br /><br />".$query."<br />";

__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
Reply With Quote
  #3 (permalink)  
Old 08-06-2008, 03:04 PM
Registered User
 
Join Date: Jul 2004
Posts: 219
I forgot to mention the problem. The pagination of 10 records per page is not happening.
I've been having problems in this for WEEKS!!! With no one to help me.
I don't understand how the while loop for paging should be set. This is what I have so far:
PHP Code:
while($row $pagedResults->fetchPagedRow()){
        echo 
"<span style='color: red;'>".$c."</span><br />";
        
//echo "{$row}";
        
print(getQuery($bigWords));
        
//echo getQuery($bigWords);
        //echo "hi";
        
$c++;
        } 
I get:
Code:
1
Array2
Array3
Array4
Array5
Array6
Array7
Array8
Array9
Array10
Array
HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEELP!!!!!
__________________
Gilgal's website:
Wheel Of God
Now easy to post scripture verses!
Portfolio
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

vB 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
Array not written properly gilgalbiblewhee Programming and Scripting 3 08-06-2008 12:51 PM
php call a function in array() gilgalbiblewhee Programming and Scripting 0 07-06-2008 12:43 PM
paging recordsets gilgalbiblewhee Programming and Scripting 18 07-03-2008 04:59 PM
10 records per page? gilgalbiblewhee Programming and Scripting 13 12-18-2007 10:17 PM
javascript: html page array with an iframe Epsilon Programming and Scripting 4 05-10-2007 05:50 PM


All times are GMT -5. The time now is 04:30 PM.

 
KickApps
Clicky Web Analytics


Subscribe to our feed | add to myYahoo!

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