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

From: Date: Fri, 25 Jan 2002 20:53:04 +0000
Subject: Re: Must results from MySQL fetches always be an Array??
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-82164@lists.php.net to get a copy of this message
try $something=settype(mysql_result($variable,0),"string"); ----- Original Message ----- From: "daniel" <daniel@inkshop.org> To: <php-general@lists.php.net> Sent: Friday, January 25, 2002 12:25 PM Subject: Re: [PHP] Must results from MySQL fetches always be an Array?? > > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#82164) next »