papaface Posted November 23, 2010 Share Posted November 23, 2010 Hey I wonder if you could help me. I have a script that scans a given webpage for the pagination numbers. Firstly I scan the page and load all the page numbers into $info['page'] as an array. I then setup a foreach loop, to go through each element (page number in the array). So the result is like: Array ( [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 ) Element 1 is page 2 etc. In the foreach loop I get it to scan page 2 of the webpage and return the page numbers. I am careful to not add a page number to the array if it already exists, and I also have another array that holds all the page numbers that has been scanned. I have this working fine. The problem I have, is that it is only looping up to page 10, despite the $info['page'] array having ( [9] => 10 [10] => 11 [11] => 12 [12] => 13 ) left in it. Why is this? Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 need to see pertinent code. Quote Link to comment Share on other sites More sharing options...
papaface Posted November 23, 2010 Author Share Posted November 23, 2010 foreach($info['Pages'] as $k => $v) { $returned = $km->fetchCatPageInfo($km->selectedcaturl."?page=".$v,array("Page"=>array('<div class="pagination">','>></a></li> </ul></div>') )); ?> Page <?php echo $v;?>:<textarea><?php print_r($returned['HTML']); ?></textarea> <?php $km->mappedpagenumbers[] = $v; foreach ($returned['Pages'] as $k2 => $v2) { if (!in_array($v2,$km->mappedpagenumbers) && !in_array($v2,$info['Pages'])) { $info['Pages'][] = $v2; } } unset($info['Pages'][$k]); } Please see above Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 i suspect this is the problem: unset($info['Pages'][$k]); can you remove it? Quote Link to comment Share on other sites More sharing options...
papaface Posted November 23, 2010 Author Share Posted November 23, 2010 Removed it and it stops in the same place. Except it just has more items in the info[pages] array $info['Pages']:Array ( [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 [12] => 13 ) mappedpagenumbers:Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 ) Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 also this bothers me: $info['Pages'][] = $v2; the code is looping over the array $info['Pages'] and modifying the array at the same time. I wouldn't mess with an array that I am in the process of looping over. if you need to update the array you are looping over, i would create another array within the loop and replace the original array after the loop exits. Quote Link to comment Share on other sites More sharing options...
papaface Posted November 23, 2010 Author Share Posted November 23, 2010 also this bothers me: $info['Pages'][] = $v2; the code is looping over the array $info['Pages'] and modifying the array at the same time. Thats right. It needs to do this so that it automatically goes through all the elements/pages. Do you think it'd be better to do: while (count($info['pages']) > 0) ? Quote Link to comment Share on other sites More sharing options...
papaface Posted November 23, 2010 Author Share Posted November 23, 2010 Issue resolved myself with foreach($info['Pages'] as $k => &$v) Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.