Solved

Order by content value and echo while respecting order

Posted on 2011-03-23
2
274 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Healthcheck 2 86
simplest php form 3 64
Before I get too far.. best way to save dates data 4 16
mysql update statement 3 0
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…
This article discusses four methods for overlaying images in a container on a web page
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now