Re: no temp var for mysql_fetch_array results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David T-G wrote:

Jeff (and John) --

...and then jeffrey_n_Dyke@xxxxxxxxx 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>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux