...

View Full Version : paging recordsets



gilgalbiblewhee
07-31-2008, 06:11 PM
http://www.sitepoint.com/article/perfect-php-pagination
I'm trying to use this model and fill in what I need to:

<?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) > 4 && !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','Sien na','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($row, 10, $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:

while($row = $pagedResults->fetchPagedRow(mysql_fetch_assoc($result))){

ST-Mike
08-01-2008, 03:38 AM
To be honest I'm tired and haven't looked at it properly, but judging from the commented out areas, shouldn't it read:


while($row = $pagedResults->fetchPagedRow()){

following creating the object?

gilgalbiblewhee
08-01-2008, 04:29 AM
To be honest I'm tired and haven't looked at it properly, but judging from the commented out areas, shouldn't it read:


while($row = $pagedResults->fetchPagedRow()){

following creating the object?
By doing that for some reason it's ignoring whatever's in the while loop.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum