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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
The only other way I see would be with a SELECT count(*) with the same where parameters and without the LIMIT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.