counting num_rows

Creating and modifying plugins.
Post Reply
Krzyzak
Regular
Posts: 41
Joined: Mon Oct 16, 2006 1:13 pm

counting num_rows

Post 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....
Sorry for my language errors- It`s not my native language.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: counting num_rows

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Krzyzak
Regular
Posts: 41
Joined: Mon Oct 16, 2006 1:13 pm

Post 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?
Sorry for my language errors- It`s not my native language.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Krzyzak
Regular
Posts: 41
Joined: Mon Oct 16, 2006 1:13 pm

Post by Krzyzak »

yeah, it`s true. So how to return an array?
BTW: what`s the second (bool) parameter in _db_query function?
Sorry for my language errors- It`s not my native language.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply