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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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