paging recordsets

Discussion in 'PHP' started by gilgalbiblewheel, Jun 25, 2008.

  1. #1
    I'm getting frustrated at this. This is not working:
    //paging
    $page = isset($_GET['page']) ? $_GET['page'] : 1;  //or you can use the ternary operator 
    
    //$resultspertpage = 10;
    $perpage = 10;// number of records per page
    $end = $page*$perpage; // present page
    $start=($page-1)*$perpage;
    /******************************************************************************/
    //$sql="SELECT count(*)totalrows  FROM bible WHERE 1=1 AND";
    $sql="SELECT * FROM bible WHERE 1=1 AND";
    $j=0;
    //to sort out all words with length less than 4 like AND, OR, BUT...
    for ($i=0; $i < count($searchTheseArr); $i++){
    	if(strlen($searchTheseArr[$i]) > 4){
    		$newSearchTheseArr[$j] = $searchTheseArr[$i];
    //j renumbers the words of length 4 and up		
    		$j++;
    	}
    }
    //sql searches only length 4 and up
    for ($j=0; $j < count($newSearchTheseArr); $j++){
    	$sql.=" CASE WHEN text_data LIKE '%" .$newSearchTheseArr[$j]. "%' THEN 1 ELSE 0 END";
    	//$sql.=" text_data LIKE '%" .$newSearchTheseArr[$j]. "%'";
    	if($j!=count($newSearchTheseArr)-1){
    		$sql.=" +";
    		//$sql.=" OR";
    	}else{
    //removes the OR from the last line and replaces with the following	
    		$sql.= " > 3";
    		$sql.= " LIMIT " . $start . ", " . $perpage;
    	}
    }
    PHP:

     
    gilgalbiblewheel, Jun 25, 2008 IP
  2. 2slick

    2slick Peon

    Messages:
    73
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try and output the $sql variable after the line and see what happens if you query it in a MySQL admin tool
     
    2slick, Jun 25, 2008 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    I get:
    But let me tell you. The option shows only page 1. Only 10 results.

    I even added an a tag going to the next page but it shows error:
     
    gilgalbiblewheel, Jun 25, 2008 IP