Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Aetherdan Posted October 17, 2017 Posted October 17, 2017 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? }
CodingJungle Posted October 17, 2017 Posted October 17, 2017 $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.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.