Solved

Sort parameter values

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

22 Experts available now in Live!

Get 1:1 Help Now