Page 1 of 1

counting num_rows

Posted: Wed Nov 01, 2006 8:56 pm
by Krzyzak
Hi. To connect with database I`m using serendipity_db_query function. But I`m looking for something like mysql_num_rows... Does something like this exists?
And second question is:
I`ve got function:

Code: Select all

function SampleFunction(){
$foo='bar';
return $foo;
}
How can I use it in my plugin? when I simply call SampleFunction I`ve got an error....

Re: counting num_rows

Posted: Wed Nov 01, 2006 9:24 pm
by garvinhicking
Hi!

s9y does not have a "num_rows". You can just use count($result) on the return variable of a serendipity_db_query, because that holds the number of results!

If you put a function within a class, you need to call it as $this->SampleFunction().

HTH,
Garvin

Posted: Thu Nov 02, 2006 8:44 pm
by Krzyzak
Hi. I couldn`t find serendipity_db_query() manual. I`ve got something like this:

Code: Select all

$q = "SELECT * FROM {$serendipity['dbPrefix']}newsletter_mail";
$t = serendipity_db_query($q, false, 'assoc');
// echo $t['mail'];
foreach($t['mail'] as $email){
//
}
but it outputs
Warning: Invalid argument supplied for foreach() in
how?

Posted: Fri Nov 03, 2006 11:36 am
by garvinhicking
Hi!

I propose to use this code:

Code: Select all

$q = "SELECT * FROM {$serendipity['dbPrefix']}newsletter_mail";
$t = serendipity_db_query($q, false, 'assoc');
print_r($t);
Then you'll see how $t is returned! It actually contains a nested array.

Best regards,
Garvin

Posted: Fri Nov 03, 2006 4:57 pm
by Krzyzak
yeah, it`s true. So how to return an array?
BTW: what`s the second (bool) parameter in _db_query function?

Posted: Fri Nov 03, 2006 5:25 pm
by garvinhicking
Hi!

The array is returned as soon as you have a valid SQL query that returns more than 0 rows.

The second parameter you can lookup by looking into include/db/mysql.inc.php in the PHPDoc comments of the serendipity_db_query() function. It indicates whether your statement expects a single row, or multiple rows.

Regards,
Garvin