Re: Creating Arrays
| From: | Morgan Curley | Date: | Wed, 11 Apr 2001 21:41:53 +0000 |
| Subject: | Re: Creating Arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48204@lists.php.net to get a copy of this message | ||
try
<?php
while( $my_data = msql_fetch_row ( $your_query_identifier ){
$the_array_I_want[ $my_data[ 0 ] ] = $my_data[ 1 ] ;
}
echo "<PRE>";
print_r( $the_array_I_want );
echo "</PRE>";
?>
Be aware that adding an element to $the_array_I_want will give it the next sequential number which would look like an ID but have nothing to do with the contents of your database.
Unless it is absolutely necessary I would recommend against doing this though. If you have record set with just a few records, no problem, 100's or 1000's of records and you should realize this array is using up your server memory. I am not sure of the mechanics of msql_fetch_row but I am pretty sure large result sets are not kept entirely in memory.
Morgan
At 12:10 PM 4/11/2001, you wrote:
I need to convert an MySQL result into an Array...somehow. Thequery returns the following:+----+-----------+ | ID | Project | +----+-----------+ | 1 | Home | | 2 | Work | | 3 | Family | | 4 | Misc. | | . | ... | | . | ... | +----+-----------+...which I want to convert into:Array(1 => "Home", 2 => "Work", 3 => "Family", 4 => Misc.", etc....);What's the best way to do this.AMK4-- W | | I haven't lost my mind; it's backed up on tape somewhere. |____________________________________________________________________ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ashley M. Kirchner <mailto:ashley@pcraft.com> . 303.442.6410 x130SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Laboratories, Inc. . eFax 248.671.0909 http://www.pcraft.com . 3550 Arapahoe Ave #6 .................. . . . . Boulder, CO 80303, USA-- 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