Solved

Sorting based on numbers

Posted on 2003-12-03
5
170 Views
Last Modified: 2013-12-25
Hi there,

Iam trying to make a sorting based on a counter but it seems that i get messup because when i try to sort some based on for example "3" all number that have a "3" will sorted as well and i dont want it. How can I sort ONLY the "3" and not the 13, 33, 23, 53, etc?
heres the code iam using

if ($yixa2 =~ 3) {
$tdtag3 = "</tr><tr>"; }
else {
$tdtag3 = "";
}

Any ideas?
Polos
0
Comment
Question by:polos
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 9872368
if ($yixa2 == 3) {
0
 
LVL 84

Accepted Solution

by:
ozo earned 25 total points
ID: 9878962
$tdtag3 = $yixa2==3&&"</tr><tr>";
0
 
LVL 3

Assisted Solution

by:rkosai
rkosai earned 25 total points
ID: 9893186
It seems that you would best be served by placing this into a hash, then sorting the hash values by number.

For purposes of example, I am going to create a hash; you would use your own data here.
my %values;
$values{23} = 'caption0';
$values{13} = 'caption1';
$values{33} = 'caption2';
$values{3} = 'caption3';


You could then use this code to print the :

foreach(sort {$a <=> $b} keys %values) {
  print "<tr><td>$values{$_}</td><td>$_</td></tr>\n";
}

This would yield:

<tr><td>caption3</td><td>3</td></tr>
<tr><td>caption1</td><td>13</td></tr>
<tr><td>caption0</td><td>23</td></tr>
<tr><td>caption2</td><td>33</td></tr>

Which is what I think you're trying to accomplish.

Otherwise, if you're only trying to find the value "3" by itself, you can use the expression,

if ($x == 3) {
  #do action
}

Good luck.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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