Re: no temp var for mysql_fetch_array results

From: Date: Tue, 11 May 2004 22:46:34 +0000
Subject: Re: no temp var for mysql_fetch_array results
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-34372@lists.php.net to get a copy of this message
David T-G wrote:
Jeff (and John) -- ...and then jeffrey_n_Dyke@Keane.com said... % ... % > $r = mysql_query($q,$dbro) ; % > $row = mysql_fetch_array($r) ; % > $i = $row[0] ; ... % >this one row (not looping), could I just % > % > $i = mysql_fetch_array($r)[0] ; % % Hi David.... Hi!
%       How about:
%       $i = mysql_result(mysql_query($q,$dbro),0);
Oooh! Cool! Just right. % HTH % Jeff Thanks & HAND :-D
Of course, this leaves the result handle open. It's best to store the result handle and free it with mysql_free_result(). If you want to get one column's data (or one row even) you may want to look into a DB abstraction layer (such as PEAR DB or MDB). Or, of course, you could write your own function. function getOne($sql, $link) { $sth = mysql_query($sql, $link); $val = mysql_result($sth, 0); mysql_free_result($sth); return $val; } -- paperCrane <Justin Patrin>

« previous php.db (#34372) next »