Solved

Order by content value and echo while respecting order

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This article discusses four methods for overlaying images in a container on a web page
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…
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.

744 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

11 Experts available now in Live!

Get 1:1 Help Now