Jump to content

How to retrieve column names ordered by value and output the result with echo


EliteIntegrity

Recommended Posts

Hi,

 

Server version - 5.0.67

the statement - that's what I hope to find out

any errors - na

currently doing not to my liking - na

tried so far - complicated sorting (for a beginner) using PHP want to use query instead.

What I want to achieve -

 

I want to be able retrieve column names from a single specified row ordered by the numerical value within those columns.

 

e.g if I have exam results table with a row (history 50, ict 100, art 70) for a student (bill).

 

I want the output of the query to be the column names ordered by the value they hold, i.e.

 

ict art history

 

 

Many thanks.

 

John

can you give use the outpuy of:

1) desc table  ( or output of SHOW CREATE TABLE ....)

2) the output of a single row of your data ?

 

Than, if that is know, the answer should not be hard.

(but i think it will be a PHP answer, and ot a MYSQL answer)

Thanks v-much. PHP was the solution.

 

Exploring your suggestions led me to discover mysql_field_name($result, x)

And the final solution.

 

...

$query="SELECT art, ict, history FROM results WHERE name='$name'";

...

$results_array=array(mysql_result($result,0,art),mysql_result($result,0,ict),mysql_result($result,0,history));

$column_names_array=array(mysql_field_name($result, 0),mysql_field_name($result, 1),mysql_field_name($result, 2));

 

array_multisort($results_array,$column_names_array);

 

print_r($column_names_array);

 

Thanks so much again.

 

John

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.