Mick23 Posted June 19, 2022 Share Posted June 19, 2022 Hi folks, I was going through the following page: And cannot get the following to work: // Get the select object $select = \IPS\Db::i()->select( '*', 'my_table', array( 'status=?', )); // Now, get the number of results returned $results = count( $select ); The $results = count ( $select) line is the problem, if I comment it out the error goes away. Am I missing something obvious here? Cheers 🙂 I should add that there are records in the table that match the query string, so results should be coming back. Link to comment Share on other sites More sharing options...
Adriano Faria Posted June 19, 2022 Share Posted June 19, 2022 status = what? Link to comment Share on other sites More sharing options...
Mick23 Posted June 19, 2022 Author Share Posted June 19, 2022 oops sorry, that's a typo there. $select = \IPS\Db::i()->select( '*', 'my_table', array( 'status=?', 0)); Link to comment Share on other sites More sharing options...
Adriano Faria Posted June 19, 2022 Share Posted June 19, 2022 $select = \IPS\Db::i()->select( '* as cnt, 'my_table', array( 'status=?', 0))->first(); The result is in $select[‘cnt’] Link to comment Share on other sites More sharing options...
teraßyte Posted June 19, 2022 Share Posted June 19, 2022 That seems okay. But how are you using the $select variable after that? Maybe that's the problem. Try posting some of the code above/below that line. Link to comment Share on other sites More sharing options...
Mick23 Posted June 20, 2022 Author Share Posted June 20, 2022 47 minutes ago, Adriano Faria said: $select = \IPS\Db::i()->select( '* as cnt, 'my_table', array( 'status=?', 0))->first(); The result is in $select[‘cnt’] Thanks - I tried this but am now getting this error: $select = \IPS\Db::i()->select('COUNT(*) as cnt', 'hangman_phrase', array('status=?', 0), array('member_id!=', $member->member_id));$result = $select['cnt']; Cannot use object of type IPS\Db\Select as array 48 minutes ago, teraßyte said: That seems okay. But how are you using the $select variable after that? Maybe that's the problem. Try posting some of the code above/below that line. I removed all the code after the count($select) line and the error still occurs. I get the feeling it's probably something so stupidly obviously I'll kick myself when I see it! Link to comment Share on other sites More sharing options...
Solution Adriano Faria Posted June 20, 2022 Solution Share Posted June 20, 2022 2 minutes ago, Mick79 said: Thanks - I tried this but am now getting this error: I don’t see the ->first() there. $count = \IPS\Db::i()->select( 'count(*)', 'hangman_phrase', array('status=0 AND member_id!=?', $member->member_id ) )->first(); print $count; You have 2 arrays there and forgot the ->first (). Mick23 and teraßyte 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts