Solved

Sort parameter values

Posted on 2013-11-14
5
276 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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