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

x
?
Solved

Sort parameter values

Posted on 2013-11-14
5
Medium Priority
?
278 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
[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
  • 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, we’ll look at how to deploy ProxySQL.
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 count occurrences of each item in an array.

670 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