Jump to content

count($select) causes a 500 server error


Go to solution Solved by Adriano Faria,

Recommended Posts

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

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

  • 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 ().

Link to comment
Share on other sites

  • Recently Browsing   0 members

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