learning_brain
New Member
- Messages
- 206
- Reaction score
- 1
- Points
- 0
You all know the old problem... 1000's of results and 1 html page...
This is easily resolved if my results were direct from a MySQL result, using LIMIT, but I can't do that....
My results are contrived from a full MySQL result, scoring each result relevance to the search string/s and adding to an array with the relevance value. This is then sorted by relevance and echo'd from the array.
I want to split the results into page sets, using array_slice($array,$startRow,$endRow), and then use a seperate navigation link with the desired page number which will pass a page number to the url....which is almost there but not quite...
I also have an additional problem. I don't think I can use foreach because I need to specify each row number in incremental order to achieve this.
So.....this is where I am now..
The pageNum and startRow work a treat but the endRow is always startRow + whatever the rows per page is.....which is wrong. I can't get my head round how to manage this if,say, there are 45 result rows on a page of e.g. 50 loops.
I'm also not sure my totalPages is right... :S
This is easily resolved if my results were direct from a MySQL result, using LIMIT, but I can't do that....
My results are contrived from a full MySQL result, scoring each result relevance to the search string/s and adding to an array with the relevance value. This is then sorted by relevance and echo'd from the array.
I want to split the results into page sets, using array_slice($array,$startRow,$endRow), and then use a seperate navigation link with the desired page number which will pass a page number to the url....which is almost there but not quite...
I also have an additional problem. I don't think I can use foreach because I need to specify each row number in incremental order to achieve this.
So.....this is where I am now..
PHP:
<?php if(isset($processed_array)){
$maxRows = 18;//specify total rows per page
$pageNum = 0;//initiate page number
if (isset($_GET['pageNum'])) {//if page number exists in url
$pageNum = $_GET['pageNum'];//page number is the number in url
}
$startRow = $pageNum * $maxRows;// start record on specified page is page number times max rows per page
$endRow = $startRow + $maxRows;
$totalPages = ceil($count_processed_array / $maxRows);
//split into page sets
$part_processed_array = array_slice($processed_array, $startRow, $endRow);
$count_part_processed_array = count($part_processed_array);
for ($row = $startRow;$row < $endRow; $row++) {
?>
<echo results from $part_processed_array)......>
<?php
}
} else {
echo "<hr/>No Results";
}//end if(isset($processed_array)){
The pageNum and startRow work a treat but the endRow is always startRow + whatever the rows per page is.....which is wrong. I can't get my head round how to manage this if,say, there are 45 result rows on a page of e.g. 50 loops.
I'm also not sure my totalPages is right... :S
Last edited: