Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted June 19, 20222 yr 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.
June 19, 20222 yr Author oops sorry, that's a typo there. $select = \IPS\Db::i()->select( '*', 'my_table', array( 'status=?', 0));
June 19, 20222 yr $select = \IPS\Db::i()->select( '* as cnt, 'my_table', array( 'status=?', 0))->first(); The result is in $select[‘cnt’]
June 19, 20222 yr 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.
June 20, 20222 yr Author 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!
June 20, 20222 yr Solution 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 ().