Re: Must results from MySQL fetches always be an Array??

From: Date: Fri, 25 Jan 2002 20:25:14 +0000
Subject: Re: Must results from MySQL fetches always be an Array??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-82160@lists.php.net to get a copy of this message
> This is sort of a "is there an easier/better way" kind of question. No > error or problem, but I'd like to know how others handle it. > > I'm fetching single elements of data from several tables, then piecing > it together. Here's an example of one element I need to fetch: > > $series = mysql_fetch_array(mysql_query("SELECT key2 FROM models WHERE > lang='$lang' AND recordname='$model'",$db)); > > Now I realize that with this function $series will always be an array, > even if it contains just one element (which it does). What I'd like to > know is, can I write that statement so that $series is created just as a > string? (So that I don't have to write "$series = $series[0];" > immediately afterwards in order to treat $series as a $string.) > > ...Rene function mysql_get_one_field($stmt,$db) { $res = mysql_query($stmt,$db); $series = mysql_fetch_array($res); mysql_free_result($res); return $series[0]; } Daniel J. Lashua

« previous php.general (#82160) next »