[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PHP create a wildcard string if GET empty

Posted on 2011-09-15
4
Medium Priority
?
381 Views
Last Modified: 2012-06-22
Hi,

I have this chunk of PHP that I needed to create a wildcard % to be used in a query if no $_GET was found:


 
<?php
if (!isset($_GET["Sub_Category"]) || empty($_GET["Sub_Category"])) {
     $scat = '%';
	} else {
	 $scat = ($_GET['Sub_Category']);
}
?>

Open in new window


Any thoughts
Thanks
Tony
0
Comment
Question by:tonypearce
[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
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
Finec earned 2000 total points
ID: 36542112
If you're looking for a shorter solution:

$scat = empty($_GET['Sub_Category']) ? '%' : $_GET['Sub_Category'];

Open in new window


Or what's the question? :)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36542119
What is the question?  The code posted here will set $scat to be a string of length=1 and content=% if the URL does not have the Sub_Category argument.  Is that what you want?
0
 

Author Closing Comment

by:tonypearce
ID: 36542144
perfect despite my bad question!!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36542171
Just a thought.. You might want to leave the questions open a little longer and maybe give a little more expository content with the question.  For example, I sense that you might be wanting to use the $scat variable in a data base query (this is a common design pattern).  Before you do that you might want to post a question here about something like, "What are the well-known best security practices that can help me keep my data base from getting destroyed or stolen by hackers?"
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 article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 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