Solved

Sort parameter values

Posted on 2013-11-14
5
264 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
Comment Utility
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
Comment Utility
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
Comment Utility
Can you please guide me here because i don't know this stuff very well.
0
 

Author Closing Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

744 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

9 Experts available now in Live!

Get 1:1 Help Now