paging recordsets

Discussion in 'PHP' started by gilgalbiblewheel, Jul 31, 2008.

  1. #1
    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','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($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>
    PHP:
    I don't think this is the right way of writing:
    	while($row = $pagedResults->fetchPagedRow(mysql_fetch_assoc($result))){
    PHP:
     
    gilgalbiblewheel, Jul 31, 2008 IP
  2. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you mean that doesn't look like PHP you know, it's because it's Object Oriented Programming. Do a google search for it with php, or look it up on some of the sites in this thread:

    forums.digitalpoint.com/showthread.php?t=957293
     
    Pos1tron, Jul 31, 2008 IP