OZONE Asylum
FAQ
How do I dump all the contents of a database table into an array?
This page's ID:
5779
Search
QuickChanges
Forums
FAQ
Archives
Register
You are editing "How do I dump all the contents of a database table into an array?"
Who can edit an FAQ?
Anyone registered may edit an FAQ.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Bitdamaged has provided a neat bit of code to create a multi-dimensional array holding all the data from a mySQL query: [code]$result = mysql_query("SELECT * FROM table"); $multi_array = array(); while($row = mysql_fetch_row($result)) { array_push($multi_array, mysql_fetch_array($row)); }[/code] [internallink=4643]Tyberius Prime[/internallink]: which is the equivalent to [code] $sresult = mysql_query("SELET * FROM table"); $multi_array = array(); while ($row = mysql_fetch_array($result)) $multi_array[] = $row; } [/code] which has the bennefit of you being able to say something like $multi_array[ 3 ][ 'fieldname' ]. But you should be aware that php usually can hold only about 8 megs of data in memory. So if you got a bigger database, you can't read it all into an array. there are few cases where you should do that anyway, as well. ------------------------- Relevant threads: [url=http://www.ozoneasylum.com/Forum12/HTML/001134.html]MySQL query for EVERYthing[/url] ___________________ [internallink=4626]Emperor[/internallink] [small][i](Added by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Emperor]Emperor [/url] on Wed 06-Aug-2003)[/i][/small] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Tyberius+Prime]Tyberius Prime [/url] on Thu 07-Aug-2003)[/i][/small] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Tyberius+Prime]Tyberius Prime [/url] on Thu 07-Aug-2003)[/i][/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »