-
How can I return fieldname?
I'm using MySQL. I'd like a query along the lines of:
SELECT * from table_name
that returns the following:
field1_name, field1_value, field2_name, field2_value, ...
How can I do this?
-
You can't do that with a simple query. You have to come up with a process to build this.
-
-
I mean that you can't dimply return a field name as a value in the select query. You have to come up with a process that builds the data set int he manner you want.
I've done it with SQL Server, and there isn't a simple way to do it.
-
What direction should I look into doing this?
-
you could use the following
$sql = "SELECT * FROM table";
$query = mysql_query($sql,$connection);
$columns = mysql_num_fields($query);
iterate through the columns
for($i = 0; $i < $columns; $i++) {
print mysql_field_name($columns,$i);
}
or the query below to return column names for the table, in conjuction with your other query and some code to do the rest.
show columns from [table name];
-
Yeah, it's much easier to get the results you want via client-side code if you are using the query in that manner.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|