NYCPHP Meetup

NYPHP.org

[nycphp-talk] mysql_num_rows() redux

Chris Bielanski Cbielanski at inta.org
Mon Feb 23 16:40:42 EST 2004


> select foo from bar where blah is not null

Actually that was my first approach - somehow my result was still 1.

Current workaround code is:

	if(mysql_num_rows($result) >= 2)
	{
		// do something
	}
	else
	{
		$row = mysql_fetch_assoc($result);
		if(is_null($row['id']))
		{
			// do something else
		}
	}

probably kludge-tastic but it hasn't bombed in the hour since I put it in...

~C
> -----Original Message-----
> From: Chris Shiflett [mailto:shiflett at php.net]
> Sent: Monday, February 23, 2004 4:35 PM
> To: NYPHP Talk
> Subject: Re: [nycphp-talk] mysql_num_rows() redux
> 
> 
> --- Chris Bielanski <Cbielanski at inta.org> wrote:
> > I *know* this has to have been covered before, but when you have
> > ostensibly no data in MySQL (that damn single row full of nulls)
> > what's the proven method forresolveing the count as zero? Obviously,
> > as I'm sure most of you know, you get a result of 1 even if there
> > is no "real" data in a MySQL table.
> 
> I assume you mean that mysql_num_rows() will return 1 when 
> there is 1 row,
> regardless of the data. This is good. Worse would be for the 
> function to
> be incorrect.
> 
> If you want to check whether a certain field is null, do it 
> in your SQL
> statement:
> 
> select foo from bar where blah is not null
> 
> Hope that helps.
> 
> Chris
> 
> =====
> Chris Shiflett - http://shiflett.org/
> 
> PHP Security - O'Reilly
>      Coming mid-2004
> HTTP Developer's Handbook - Sams
>      http://httphandbook.org/
> PHP Community Site
>      http://phpcommunity.org/
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
> 



More information about the talk mailing list