Skip to content
bonsak edited this page Nov 20, 2012 · 1 revision

data()

Return an array of all rows returned from a find() call. Most of the time, you will want to loop through data using fetch() instead of using this function.

public function data ()

Returns

(array) or (bool) An array of all rows returned from a find() call, or false if no items returned

Example

<?php
    $params = array(
        'orderby' => 't.birth_date ASC',
        'where'   => 't.birth_date < "1972"',
        'limit'   => -1 // Return all rows
    );

    // find() will be called when you give an array to pods()
    $people = pods( 'people', $params );

    $all_rows = $people->data();

    if ( !empty( $all_rows ) ) {
        foreach( $all_rows as $this_person ) {
    ?>
    <h2><?php echo $this_person->name; ?></h2>
    <p>Favorite Color: <?php echo $this_person->favorite_color; ?></p>
    <br />
<?php
        }
    }
    else
        echo '<strong>No people found.</strong>';
The above example will output:
<h2>Fred Flintstone</h2>
Favorite Color: Blue
<br />
<h2>Phil Lewis</h2>
Favorite Color: Yellow
<br />

Available Since Version

2.0+

Source File

data() is located in /pods/classes/Pods.php

See Also