Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Order by content value and echo while respecting order

Posted on 2011-03-23
2
Medium Priority
?
302 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
[X]
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
2 Comments
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 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