EliteIntegrity Posted March 19, 2010 Share Posted March 19, 2010 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 https://forums.phpfreaks.com/topic/195790-how-to-retrieve-column-names-ordered-by-value-and-output-the-result-with-echo/ Share on other sites More sharing options...
jskywalker Posted March 20, 2010 Share Posted March 20, 2010 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) Link to comment https://forums.phpfreaks.com/topic/195790-how-to-retrieve-column-names-ordered-by-value-and-output-the-result-with-echo/#findComment-1029144 Share on other sites More sharing options...
fenway Posted March 20, 2010 Share Posted March 20, 2010 Yeah, you can't do that in mysql. Link to comment https://forums.phpfreaks.com/topic/195790-how-to-retrieve-column-names-ordered-by-value-and-output-the-result-with-echo/#findComment-1029307 Share on other sites More sharing options...
EliteIntegrity Posted March 21, 2010 Author Share Posted March 21, 2010 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 https://forums.phpfreaks.com/topic/195790-how-to-retrieve-column-names-ordered-by-value-and-output-the-result-with-echo/#findComment-1029490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.