Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sorting based on numbers

Posted on 2003-12-03
5
Medium Priority
?
178 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
[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
5 Comments
 
LVL 84

Expert Comment

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

Accepted Solution

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

Assisted Solution

by:rkosai
rkosai earned 100 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

664 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