How to change a page from Pagination to Infinite Scroll?

I’m using a PHP script for a web site, and when the web site is keyword-searched for videos the results apppear on several pages.How can the search results appear in infinte-scroll instead of by pagination? Here’s the code. Pagination code is about half way down and then just past that it shows Pagination Plus. Any help will be appreciated.

    <?php
error_reporting(0);
///////////////////////////////////////////////////////////////////////////////////////

include_once ('classes/config.php');
include_once ('classes/sessions.php');

$default_album_pic = $config['default_album_pic'];

///////////////////////////////////////////////////////////////////////////////////////
// changed search server method to get to get rid of cache expired error

if( ( $_SERVER['REQUEST_METHOD'] != 'GET') ) dieNice();



///////////////////////////////////////////////////
// C-dd
////////

$_SESSION['searched'] = $_GET['keyword'];
$prch = $_GET['p'];

if ($user_id == "") {

	$new_temp = "themes/$user_theme/templates/search_results_guest.htm";


}elseif ($prch == "1") {

	$new_temp = "themes/$user_theme/templates/search_results_paid.htm";

}else{

	$new_temp = "themes/$user_theme/templates/search_results.htm";

}

$queryString = strtolower($_SERVER['QUERY_STRING']);
if (strstr($queryString,'%20union%20') OR strstr($queryString,'/*')) dieNice();

$referer	= mysql_real_escape_string( $_SERVER['HTTP_REFERER'] );
if ( $referer == '' ) dieNice();
if ( !ereg ($_SERVER['SERVER_NAME'], $referer) ) $flag_stop++;
if ( !ereg ($base_url, $referer) ) $flag_stop++;
if ( $flag_stop == 2 ) dieNice();

$keywords	= $_GET['keyword'];
$keywords	= str_replace('&#039;s', "", $keywords);
$keywords	= str_replace('+', " ", $keywords);

$debug_log_file = 'logs/search_log.txt';

if (@file_exists($debug_log_file)) {
	$fo = @fopen($debug_log_file, 'a');
     	@fwrite($fo, $keywords);
     	@fclose($fo);

} else {
     	$fo = @fopen($debug_log_file, 'w');
     	@fwrite($fo, $keywords);
     	@fclose($fo);
}

$keyword 	= mysql_real_escape_string($keywords);
$channel	= mysql_real_escape_string( $_GET['type'] );

if ($type == '') {
    $keyword    = mysql_real_escape_string($keywords);
        $type        = mysql_real_escape_string($_GET['type']);
}

if ($keyword == '' | $type == '' ) {
    $type        = 'videos';
    $keyword     = 'none';
}


$type_videos	= 1;
$row_id		= 'video_id';
$media_comments	= 'videocomments';
$type_query_rows 	= 'indexer, video_id, channel_id, thumb_string, title, title_seo, date_uploaded, user_id, video_length, approved, public_private, description, tags, number_of_views';

$tag_cloud 		= make_tag_cloud( $get_type );
$tag_cloud_block 	= $tag_cloud[1];

if (is_numeric($channel)) {
	$page_guery	= "SELECT indexer FROM videos WHERE approved = 'yes' AND public_private = 'public' AND channel_id = $channel AND (title like '%$keyword%' or tags like '%$keyword%' or description like '%$keyword%')";
	$search_query	= "SELECT $type_query_rows FROM videos WHERE approved = 'yes' AND public_private = 'public' AND channel_id = $channel AND (title like '%$keyword%' or tags like '%$keyword%' or description like '%$keyword%') LIMIT "; // $set_limit, $limit";
} else {
	$page_guery	= "SELECT indexer FROM videos WHERE approved = 'yes' AND public_private = 'public' AND (title like '%$keyword%' or tags like '%$keyword%' or description like '%$keyword%')";
	$search_query	= "SELECT $type_query_rows FROM videos WHERE approved = 'yes' AND public_private = 'public' AND (title like '%$keyword%' or tags like '%$keyword%' or description like '%$keyword%') LIMIT "; // $set_limit, $limit";
}
$query_get_type	= 'videos';

	$limit	= (int) mysql_real_escape_string( $config['search_page_limits'] );
    	$pagination 	= pagination($page_guery, $limit);
    	$set_limit		= $pagination[0]['set_limit'];
    	$total_pages	= $pagination[0]['total_pages'];
    	$current_page 	= $pagination[0]['current_page'];
    	$total_records 	= $pagination[0]['total_records'];
    	$next_page 		= $pagination[0]['next_page'];
    	$prev_page 		= $pagination[0]['prev_page'];
    	$nl 			= $pagination[0]['nl'];
    	$pl 			= $pagination[0]['pl'];

    	$result_search 	= array();
    	$sql			= $search_query . $set_limit .','. $limit;
    	$query 		= @mysql_query($sql);

    	$results_of 	= $current_page * $limit;
    	$results_show 	= $set_limit + 1;

    	if ( $results_of > $total_records )	$results_of = $total_records;
    	if ( $set_limit == 0 ) 			$results_show = 1;
    	if ( $total_records == 0 ) 		$results_show = 0;

 		define($get_type, true);

    	while ($result1 = @mysql_fetch_array($query)) {
    		$media_id		= mysql_real_escape_string($result1['indexer']);
    		$sql2 		= "SELECT indexer FROM $media_comments WHERE $row_id = $media_id";
       		$query2 		= @mysql_query($sql2);
        	$comments_number	= @mysql_num_rows($query2);
        	$comments_array 	= array('comments' => $comments_number);

        	$id	= $media_id;
			$stars_array = stars_array($media_id);

        	// we need dynamic media image query
        	$result_image	= 'videos';
       		$result2	= @array_merge($result1, $comments_array, $stars_array);
        	$result_search[] 	= $result2;
    	}

//PAGINATION PLUS
$url = 'search.php';
$additional_url_variable = "?keyword=$keyword&type=$type&page=";
include_once('includes/pagination.inc.php');
//PAGINATION PLUS >> end

// checking for any error codes
$codes = $_GET['code'];
$error_code = errorcodes($codes);

if (!empty($error_code)) {
	$blk_notification = $error_code['error_display'];
     	$message_type = $error_code['error_type'];
     	$error_message =$error_code['error_message'];
}

// create dynamic template words
$url_link	= 'videos';

$get_type 		= ucwords($get_type);
$get_type_word	= substr($get_type, 0, -1);
$page_title		= $config['site_name'] . ' ' . $get_type_word . ' ' . $lang_search . ' ' . $lang_results . ' ' . $lang_for . ' ' . $keyword;
$template		= "themes/$user_theme/templates/main_1.htm";
//$inner_template1 	= "themes/$user_theme/templates/search_results.htm";
$inner_template1 	= $new_temp;
$TBS			= new clsTinyButStrong;
$TBS->NoErr 	= true;

$TBS->LoadTemplate("$template");

$TBS->MergeBlock('blkfeatured', $result_search);

$TBS->Render = TBS_OUTPUT;
$TBS->Show();
@mysql_close();
die();

function dieNice() {
	header("Location: index.php");
	die();
}

?>

You need some form of AJAX to change to infinite scrolling. PHP can’t do it alone.

Scott

Thanks for your reply.
Can you elaborate on how complex or simple that would be?

A scroll event listener that checks how close the bottom of the current page is and if less than a certain amount does a call to the server to retrieve more content to add to the bottom.

You’d need to track how many calls the page had already made to as to know what piece of content to retrieve next.

If you’re using jQuery there’s an article on SitePoint :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.