?
Solved

Order by content value and echo while respecting order

Posted on 2011-03-23
2
Medium Priority
?
298 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

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.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 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