Jump to content

Recommended Posts

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 !!

 

 

Link to comment
https://forums.phpfreaks.com/topic/148822-solved-an-easier-way-to-get-data-out/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.