Jump to content

Search the Community

Showing results for tags 'while loop'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 1 result

  1. 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!
×
×
  • Create New...