Jump to content

Assign Fields


EchoFool

Recommended Posts

Is there a quick method to assigning fields to an Array ?

 

Say i have SELECT * FROM table

 

Now say theres 30 field, i don't want to be doing:

 

$UserID = $row['UserID'];$Username = $row['Username'];  for all 30 fields.

 

Is there a way to loop them into an array? Would save so much time.

Link to comment
https://forums.phpfreaks.com/topic/185740-assign-fields/
Share on other sites

What's wrong with $row['UserID']? It is a perfectly valid variable.

 

By assigning it to another variable $UserID = $row['UserID'], you are just wasting processing time and memory.

 

Okay good point on that front - Judging from your answer that means the loop option is not possible ? :P

Link to comment
https://forums.phpfreaks.com/topic/185740-assign-fields/#findComment-980753
Share on other sites

Okay ill do a small example

 

Table:

UserID | Username | Password | Email

---------------------------

 

Query:

 

SELECT * FROM table

 

Now in php currently i do:

 

$array = array($row['UserID'],$row['Username']  etc etc

 

But if theres some 30 + fields in the table, it gets a bit annoying having to write it all out, so i wanted to see if i can create the array from while looping some how - so that i don't have to type out giant arrays all the time. The reason i put them in an array is because this occurs in a function.

 

Which i then place the array in return().

Link to comment
https://forums.phpfreaks.com/topic/185740-assign-fields/#findComment-980757
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.