views:

34

answers:

1

I've created my select:

$select = $zdb->select()
              ->from(array("b" => "blogs"),
                     array("id", "active", "updated_by", "title", "synopsis", "create_date", "body"))
              ->join(array("u" => "users"),
                     'b.updated_by = u.id',
                     array("first_name", "last_name"))
              ->where("u.blogger = ?", 1)
              ->where("b.publish_date > ?", '2020-01-01')
              ->where("b.active = ?", 1)
              ->group("b.id")
              ->order("b.publish_date DESC")
              ->limit(5);

and I want to pull the data back a row at a time:

$stmt = $db->query($select);

while ($asset = $stmt->fetch()) {
    // do stuff
}

How can I check to make sure that there are rows, without returning the entire resultset?

A: 

Using the select you already have, something like that should help you parse every entry

$rows = $zdb->fetchAll($select);

foreach($rows as $row){
    ...
}

To get the values you just have to do $row['fieldName'] where fieldName is the name of the field in your database

Jeff
Except that I don't want to fetch everything back, as I suggested in the title of the question. I want to know how many rows I can expect, via the stmt.
gms8994
The only other way I see would be with a SELECT count(*) with the same where parameters and without the LIMIT
Jeff