phpcodec Posted May 26, 2008 Share Posted May 26, 2008 function pagination($current_page,$total_rows) { $current_page = (!is_numeric($current_page))?'1':$current_page; $results_per_page = '24'; echo '<b>Select A Page:</b><br />'; if($total_rows=='0') { echo 'No Pages Available'; $start = '0'; $finish = '0'; } else { $total_pages = ceil($total_rows/$results_per_page); if($current_page>'1') { echo '<a href="?page='.($current_page-1).'"><<Previous</a> '; } for($i='1';$i<=$total_pages;$i++) { if($current_page==$i) { echo '<a href="?page='.$i.'"><b>['.$i.']</b></a> '; } else { echo '<a href="?page='.$i.'">'.$i.'</a> '; } } if($current_page<$total_pages) { echo '<a href="?page='.($page+1).'">Next>></a> '; } $start = $current_page*$results_per_page-$results_per_page; $finish = $results_per_page; } } pagination($_GET['page'],$row); echo $start.' '.$finish; When i echo $start and $finish after i call the function pagination() which assigns $start and $finish it does'nt show anything, how can make this work? Link to comment https://forums.phpfreaks.com/topic/107313-function-help/ Share on other sites More sharing options...
BlueSkyIS Posted May 26, 2008 Share Posted May 26, 2008 by default variables inside a function are not global in scope (they are not available outside of the function.) i would return the variables in an array: // inside function $start = $current_page*$results_per_page-$results_per_page; $finish = $results_per_page; return array($start, $finish); } } // end of function // calling function: list($start2, $finish2) = pagination($_GET['page'],$row); echo $start2.' '.$finish2; Link to comment https://forums.phpfreaks.com/topic/107313-function-help/#findComment-550202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.