How would i do this? (MySQL & PHP)?

Phil

New member
Well i am trying to do somthing a bit complicated to explain so i'll do my best...

I have a mysql table where the ammount of fields can vary and i will not know the name of them. I wanted to add the field name and the content into an array (example below)

+---------------+-----------------+----+----+---+----+
| Username | Email | A | B | C | D | <=== field titles
+---------------+-----------------+----+----+---+----+
| Phil | [email protected] | w | x | y | z | <====example record
+---------------+-----------------+-----+---+---+-----+

becomes

$profile = array (
"username" => "Phil",
"email" => "[email protected]",
"a" => "w",
"b" => "x",
"c" => "y",
"d" => "z"
);

i on there is going to be either a while or a foreach loop involved and i know the array would look different cause you would need some code in there, its just a representation of how the data would end up inputted in the array.

hope its clear enough to understand!

-Phil
Thanks guys for the help!

Live connector thanks for the code worked perfectly!
 
Phil,

You need to create a query that will bring all fields from the database (select * from yourtable), run it from a php script, get the data and manipulate it on your php script.

Look on PHP.net for PDO, MySQL and MySQLi. They should show you a bunch of examples on doing this.
 
Back
Top