mysql_num_rows

Discussion forum for MOD Writers regarding MOD Development.
tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium

mysql_num_rows

Post by tommekemc »

is there any dbal for mysql_num_rows?
I found sql_num_queries(), but this is something else...
or can I just use mysql_num_rows?
my sig
my projects

images deleted because of the 6kb (wtf?) rule...
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: mysql_num_rows

Post by david63 »

The only one I can see is sql_affectedrows() which may give you what you want.
tommekemc wrote:can I just use mysql_num_rows?
Only if you do not plan releasing it as part of a mod.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium

Re: mysql_num_rows

Post by tommekemc »

well, that's the problem.
what if I need to use it in my mod?
(did it in another way now...)
I think sql_affectedrows() returns the rows that have changed, isn't it?
my sig
my projects

images deleted because of the 6kb (wtf?) rule...
janmyszkier
Registered User
Posts: 294
Joined: Tue Oct 09, 2007 4:53 pm

Re: mysql_num_rows

Post by janmyszkier »

no it returns the number of rows that are inside the result of an sql query
tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium

Re: mysql_num_rows

Post by tommekemc »

Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier .
and if I check the code it says:

Code: Select all

return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false;
ir means: return mysql_affected_rows (described on top) or return false...
this does not return the amount of rows you've stored in your var...
my sig
my projects

images deleted because of the 6kb (wtf?) rule...
janmyszkier
Registered User
Posts: 294
Joined: Tue Oct 09, 2007 4:53 pm

Re: mysql_num_rows

Post by janmyszkier »

works fine on SELECT though... just applied it to my mod.
tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium

Re: mysql_num_rows

Post by tommekemc »

well, ok :)
thanx!
my sig
my projects

images deleted because of the 6kb (wtf?) rule...
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 29002
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: mysql_num_rows

Post by Paul »

janmyszkier wrote:works fine on SELECT though... just applied it to my mod.
Only you should not use i on a SELECT, your MOD will be denied for that :).

You actually dont need num_rows, there are always replacements that can be used instead, sizeof at the full resultset, or a do while to check if there is any result, or a COUNT query.
janmyszkier
Registered User
Posts: 294
Joined: Tue Oct 09, 2007 4:53 pm

Re: mysql_num_rows

Post by janmyszkier »

so why do PHPBB code has SELECT and affectedrows in it while it is forbidden? I bet i saw it somewhere, becuase i copied the idea from phpbb to my mod :)
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 29002
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: mysql_num_rows

Post by Paul »

phpBB3 never uses affected rows on a select. Its not meant for select, its meant for update/delete/insert only.
janmyszkier
Registered User
Posts: 294
Joined: Tue Oct 09, 2007 4:53 pm

Re: mysql_num_rows

Post by janmyszkier »

so i guess the only way is a 'while' ?
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 29002
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: mysql_num_rows

Post by Paul »

it depends on what you want to use it for, there are several replacements for in certian situations.
tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium

Re: mysql_num_rows

Post by tommekemc »

me again, I'm wondering how I can check if there's anything fetched or nothing, how do I do that?
for example:

Code: Select all

if(mysql_num_rowq($sql)==1){
//do code
}else{
//do something else
}
my sig
my projects

images deleted because of the 6kb (wtf?) rule...
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34459
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run

Re: mysql_num_rows

Post by A_Jelly_Doughnut »

If nothing was fetched, $db->sql_fetchrow will return an empty array. So

Code: Select all

if (!($row = $db->sql_fetchrow($result)))
{
   // The query had no results
}
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium

Re: mysql_num_rows

Post by tommekemc »

thanx for your reply!
wasn't 100% sure, so I thought I'dd ask it to the pro's :p
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

Return to “[3.0.x] MOD Writers Discussion”