Solved

Sort parameter values

Posted on 2013-11-14
5
272 Views
Last Modified: 2013-11-19
Hello,

I have an mysql query which need to be filtered by the values from a parameter that looks like this: <url>?featuresId=18, 2, 50

The issue is that i need the values to be ordered ascending in order to display the correct results. The received values should be like (2,18,50)

My sql query looks something like this:
get_features_query = "select * from features where feature_name like '%|" . str_replace(",", "|%|", $HTTP_GET_VARS['featuresId']) . "|%'"

Thanks
0
Comment
Question by:b0byan
  • 3
5 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 39647530
try:
$temp=explode(',', $HTTP_GET_VARS['featuresId']);
foreach($temp as $index=>$value)
{
	if(is_int($value))
	{
		$temp[$index]=(int)$value;
	}
	else
	{
		unset($temp[$index]);
	}
}
asort($temp);
$get_features_query = "select * from features where feature_name like '%|" . implode("|%|", $temp) . "|%'";

Open in new window

0
 

Accepted Solution

by:
b0byan earned 0 total points
ID: 39647574
Hi,

your array returns empty values. i don't know why. I've tried to echo it and i get no values.

$temp=explode(',', $HTTP_GET_VARS['featuresId']);
foreach($temp as $index=>$value)
{
      if(is_int($value))
      {
            $temp[$index]=(int)$value;
      }
      else
      {
            unset($temp[$index]);
      }
}
asort($temp);

echo '%|"' . implode("|%|", $temp) . '"|%';
0
 

Author Comment

by:b0byan
ID: 39647613
Can you please guide me here because i don't know this stuff very well.
0
 

Author Closing Comment

by:b0byan
ID: 39658829
Thanks. Took me a while to understand how to echo an array
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

816 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

7 Experts available now in Live!

Get 1:1 Help Now