grissom Posted March 10, 2009 Share Posted March 10, 2009 Hi all I have a large database with several fields and I've doing the old "while" statement to extract each of the fields and assign them to a php variable name eg : ( a bit of pseudocode) while($get_client_row = mysql_fetch_array($get_this_client)) { $status = $get_client_row['status']; $coname = $get_client_row['coname']; $address_1 = $get_client_row['address_1']; and so on and so on etc. a great long-winded thing which goes on for about 20 lines, as there are about 20 fields in the database My question is, is there a faster way to do this to go through the whole database and assign a variable name with the name of the field equal to the contents of the field Something like (and here comes some more pseudo code) while($get_data_row = mysql_fetch_array($get_this_array)) { FOR EACH field_name in $get_data_row { $here_we_assign_a_variable_name_equal_to_the_name_of_the_field = $get_data_row['name_of_the_field']; } So that, for example if the first field was called 'contacts' and the second field was called 'name' then it would automatically riffle through the database and do $contacts = $get_data_row['contacts'] $name = $get_data_row['name'] etc etc without me having to type them all in ? many thanks !! Quote Link to comment https://forums.phpfreaks.com/topic/148822-solved-an-easier-way-to-get-data-out/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 10, 2009 Share Posted March 10, 2009 It depends on how you are using the data. $get_client_row['status'], $get_client_row['coname'], and $get_client_row['address_1'] are all perfectly usable variables and making a copy into $status, $coname, and $address_1 (repeat 20 more times) is actually just a waste of processing time and doubles the amount of memory used by that data. $get_data_row is an array and you can use php array functions on it, like the foreach() loop in order to process each field. Quote Link to comment https://forums.phpfreaks.com/topic/148822-solved-an-easier-way-to-get-data-out/#findComment-781497 Share on other sites More sharing options...
grissom Posted March 10, 2009 Author Share Posted March 10, 2009 Thanks PFM, I'm gonna give that a whirl. All the very best Quote Link to comment https://forums.phpfreaks.com/topic/148822-solved-an-easier-way-to-get-data-out/#findComment-781524 Share on other sites More sharing options...
grissom Posted March 10, 2009 Author Share Posted March 10, 2009 Yup, that works a treat. Thanks once again : ) Quote Link to comment https://forums.phpfreaks.com/topic/148822-solved-an-easier-way-to-get-data-out/#findComment-781568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.