mysql_fetch_row options

From: Date: Sat, 26 Oct 2002 10:23:23 +0000
Subject: mysql_fetch_row options
Groups: php.general 
Request: Send a blank email to php-general+get-121522@lists.php.net to get a copy of this message
There's got to be a better way to go about this: I am constantly doing mysql queries where I am doing a count(), so a sample query would be like this: "select count(*) from database". I'm expecting only ONE value back exactly, and that's the count results. However, to get this data into a variable, i'm having to write code like this: $result = mysql_query("select count(*) from database", $db); $myrow = mysql_fetch_row($result); $staticvar += $myrow[0]; $staticvar will never be an array, it's just a simple variable storing a number. I *could* do it like this: $result = mysql_query("select * from database", $db); $staticvar += mysql_num_rows($result); However, the mysql query will be much, much slower if I do it like this. Basically, what I'm asking, is how to do something like: $staticvar += mysql_fetch_row($result); I want to eliminate step two, and I don't want to involve any temporary arrays when there's always just one value. Any suggestions? Thanks a bunch!

« previous php.general (#121522) next »