Jump to content

Iterate through rows of db query


Aetherdan

Recommended Posts

I can't seem to correctly iterate through the rows of a db query. Am i doing something wrong with the below example?

try {
    $posts = \IPS\Db::i()->select('*', 'forums_posts', array('topic_id=?', $topic))->first();
}
catch( \UnderflowException $e ) {
    // Query failed
}

foreach ( $posts as $post ) {
	// not working?
}

 

Link to comment
Share on other sites

$posts = \IPS\Db::i()->select('*', 'forums_posts', array('topic_id=?', $topic));

foreach ( $posts as $post ) {
	// not working?
}

->first() will get you the first matching record, and will throw an exception if nothing is to be found. this way, there is no exception throw, it just wont have anything or iterator over. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...