Search the Community
Showing results for tags 'while loop'.
-
Hi all, Before you ask, this is part of my learning process so am not busy breaking somebody's site OK, I am now comfortable enough using foreach loops in PW. I am now onto "while loops". How can I replicate the following "while loop" code in PW? I've learnt that it is common to use similar code to access tables in a database. While there are still results, keep on getting them and add them to an array... $rows = array(); $results = $db->query("SELECT id, name, data FROM some_table"); while($row = $results->fetch_array()) { $rows[] = $row; } Now, in my case, my data is in PW as normal PW pages. I do not need to do the $db->query thing. I can use PW selectors. The $results bit is straightforward, .e.g using $pages->find('something'); I also know $pages->find(); will return an array (PageArray). Where am getting stumped is how to use the while loop to do the same thing the above code is doing but using PW API. Specifically, what I don't get is how to replicate the $results->fetch_array() bit using PW API. I have Googled the forum and haven't found anything but examples of querying external tables as shown above. I have also checked the API documentation but nothing has worked for me yet. I am either getting endless loops (white screen) or no items get added to the array . Here's my question in code. I know the $results->fetch_array() will not work here $rows = array(); $results = $pages->find('template=basic-home, limit=20'); while($row = $results->fetch_array())//how to replicate this fetch_array bit? { $rows[] = $row; } Or, should I not use the while loop in such a case? Use something else? Thanks!