Re: help: column into array?

From: Date: Thu, 15 Feb 2001 23:48:24 +0000
Subject: Re: help: column into array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-40024@lists.php.net to get a copy of this message
> how can I reference a result set by array index numbers??? > id_field field > --------|-------- > 1 first > 1 second > 1 third > 2 fourth > 2 fifth > > how can I do something like this: > > $array=mysql_db_query($database, $sql, $link_id); > > echo array[0]; file://I want this to print "first" > echo array[1]; file://I want this to print "second" > > I know mysql_fetch_array pulls a ROW into an array, but in this case the row > is only one item wide, so I essentially want column results in an indexed > array. I don't think you can really do that directly. Pretty much the whole database concept of row/column is that you want to use your data the way you set it up in the database in the first place. You *could* just iterate through your rows and *build* an array: while(list($item) = mysql_fetch_row($result)){ $array[] = $item; } and use that array for the rest of your program... -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#40024) next »