Reputation: 439
I have a search field in the page. But if there is no matching results, it is throwing an error "Fatal error: Call to a member function show() on a non-object". I have attached the screenshot.
<?php
if ( isset($_REQUEST['usersearch']) && $_REQUEST['usersearch'] )
printf( '<span class="subtitle">' . __('Search results for “%s”') .
'</span>', esc_html( $_REQUEST['usersearch'] ) );
?>
But the error line is (228th line):-
<div class='tablenav-pages'>
<?php echo $p->show(); // Echo out the list of paging. ?>
</div>
I need to remove the error on search result. It should simply show "No items found".
function pager($items)
{
global $limit;
global $p;
global $searchTerm;
global $pageLimit;
if($items > 0) {
$p = new pagination;
$p->items($items);
$p->limit($pageLimit); // Limit entries per page
$p->target("admin.php?page=User Control&usersearch=".$_REQUEST['usersearch']."&page-limit=".$_REQUEST['page-limit']);
$p->currentPage($_GET[$p->paging]); // Gets and validates the current page
$p->calculate(); // Calculates what to show
$p->parameterName('paging');
$p->adjacents(1); //No. of page away from the current page
if(!isset($_GET['paging'])) {
$p->page = 1;
} else {
$p->page = $_GET['paging'];
}
//Query for limit paging
$limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
} else {
echo "No Record Found";
}
}
Upvotes: 0
Views: 64
Reputation: 1293
Your getting the error because your attempting to show a object that is undefined...use a statement to check...this is the premise.
<div class='tablenav-pages'>
<? if(is_object($p)){echo $p->show();} ?>
</div>
Upvotes: 1