Re: PHP/MySQL & Control Structures -> if (mysql_query())

From: Date: Wed, 21 Mar 2001 06:11:21 +0000
Subject: Re: PHP/MySQL & Control Structures -> if (mysql_query())
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-44887@lists.php.net to get a copy of this message
On Wed, 21 Mar 2001 16:15, Mike Gifford wrote: > Hi David, > > I counted the number of rows using mysql_numrows(), but I've been told > that count() is way faster. Unfortunately, I can't seem to get count > working.. Any ideas? > > <?php > echo mysql_numrows(mysql_query("select * FROM phPetition",$db)); > > // This should be faster, but doesn't seem to work > // echo count(mysql_query("select * FROM phPetition",$db)); > ?> Who told you that? Refer them to the manual which will tell them that count will 'count the elements in a variable' or in other words tell you how many elements an array has. mysql_numrows is the way to go here. Oh, hang on, maybe they mean the SQL count - "SELECT COUNT(*) as numrows FROM phPetition" and then look at the value of numrows Yes, this can be quicker (for varying values of quicker) depending on the number of rows in the table, the way the table is indexed etc etc. But if it would mean another call to the database over and above another query then you may be offsetting any savings you get. For the case of one or zero rows, it's probably insignificant. Unless you are running this on an old Altos 8086 or somesuch? In a nutshell, if something is giving you a noticable slowdown, it probably isn't that difference. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#44887) next »