Jump to content

Flipping data in a table using a MySQL query and posting to a PHP form


general_paton99

Recommended Posts

I am new to MySQL and PHP so please forgive me if this is a stupid questions.

How can I flip a tables data using a query?

Current table (actual table has more fields)

field_id  user_id  xdata
24        5          Bob
25        5          Villa
26        5          1970-06-12
24        6          Susan
25        6          Summers
26        6          1970-06-10

How can I get it to look like below using a query?  I can't change the actual table, because it's called on by a much bigger system.

user_id    24 AS first_name  25 AS last_name    26 AS birthday
5            Bob                    Villa                    1970-06-12
6            Susan                  Summers            1970-06-10

Once queried, I then need to get it into a form which an admin can edit and update the respective fields.

Thanks for any help!
Once you query the database you can display the contents of the query where ever you you want by simply echoing them at the right places. For example;

[code=php:0]
$query=mysql_query("SELECT field_id, user_id, xdata FROM table_name");
$data=mysql_fetch_assoc($query);

//you can then echo the values
echo $data['user_id'];
[/code]

Not sure exactly what you want to do with the information. But that is a simple way. Once you get the data from the table you can dump it into variables and display it however you want.

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.