?
Solved

PHP create a wildcard string if GET empty

Posted on 2011-09-15
4
Medium Priority
?
377 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

Industry Leaders: 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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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

762 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