Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Order by content value and echo while respecting order

Posted on 2011-03-23
2
286 Views
Last Modified: 2013-12-13
Example:
in table rank I have three col A,B,C
A has a value of 2, B has a value of 6 and C has a value of 1
from there
how can I write the PHP part to echo the name of the col and the value
from higher to lower
so it will echo B: 6  A: 2 C: 1
Do I have to go with a switch and test for all combos (9 cases) that sounds heavy)
much more if in the future I add one or two more ranking possibilities.
0
Comment
Question by:array007
2 Comments
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 500 total points
ID: 35198269
If you put your columns into an array you can sort the array and then print...  Something like:

// Create a sample data set
$column['A'] = 2;
$column['B'] = 6;
$column['C'] = 1;

asort($column);

foreach ($column as $key => $value){
     echo $key.': '.$value;
}
0
 
LVL 1

Author Closing Comment

by:array007
ID: 35198405
Good idea thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question